易截截图软件、单文件、免安装、纯绿色、仅160KB

SQL Server函数大全

  --聚合函数
use pubs
go
select avg(distinct price)  --算平均数
from titles
where type='business'
go 
use pubs
go
select max(ytd_sales)  --最大数
from titles
go 
use pubs
go
select min(ytd_sales) --最小数
from titles
go 
use pubs
go
select type,sum(price),sum(advance)  --求和
from titles
group by type
order by type
go 
use pubs
go 
select count(distinct city)  --求个数
from authors
go 
use pubs
go
select stdev(royalty) --返回给定表达式中所有值的统计标准偏差
from titles
go 
use pubs
go
select stdevp(royalty) --返回表达式中所有制的填充统计标准偏差
from titles
go 
use pubs
go
select var(royalty) --返回所有值的统计方差
from titles
go 
use pubs
go
select varp(royalty) --返回所有值的填充的统计方差
from titles
go 
--数学函数 
select sin(23.45),atan(1.234),rand(),PI(),sign(-2.34) --其中rand是获得一个随机数
--
配置函数
SELECT @@VERSION --获取当前数据库版本
SELECT @@LANGUAGE --当前语言
--
时间函数
select getdate() as 'wawa_getdate' --当前时间
select getutcdate() as 'wawa_getutcdate' --获取utc时间
select day(getdate()) as 'wawa_day' --取出天
select month(getdate()) as 'wawa_month' --取出月
select year(getdate()) as 'wawa_year' --取出年
select dateadd(d,3,getdate()) as wawa_dateadd --加三天,注意'd'表示天,'m'表示月,'yy'表示年,下面一样
select datediff(d,'2004-07-01','2004-07-15') as wawa_datediff --计算两个时间的差
select datename(d,'2004-07-15') as wawa_datename --取出时间的某一部分
select datepart(d,getdate()) as wawa_


相关文档:

SQL语句得到存储过程关联哪些表名


 
 
SELECT DISTINCT '['+user_name(b.uid)+'].['+b.name+']' AS 对象名,b.type AS 类型
from sysdepends a,sysobjects b
WHERE b.id=a.depid
    AND a.id=OBJECT_ID('过程名');
 
 
EXEC SP_DEPENDS '过程名';
 
......

sql中 in 、not in 、exists、not exists 用法和差别

exists (sql 返回结果集为真)
not exists (sql 不返回结果集为真)
如下:
表A
ID NAME
1    A1
2    A2
3  A3
表B
ID AID NAME
1    1 B1
2    2 B2
3    2 B3
表A和表B是1对多的关系 A.ID => B.AID
......

几个常用的,对表的某一列进行操作的SQL命令

适用:ORACLE
 修改列名
          alter table xxx rename column aaa to bbb;
删除一列
          alter table xxx drop column aaa;
增加一列
          alter ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号