sum求和:select sum(a) from table1 group by b 依據b列為a列求和
distinct去除重復:select distinct(a) from table1 顯示表中的a列,不顯示重復項
select distinct a,b from table1 顯示表中不重復的a,b列
cast轉換數據類型:select cast a asdecimal(18,2) from table1 將選出的數據轉換成知道類型
case函數:select a,b=case when b<500 then 0 elseb end ,c from table 選出b列,選出的數據小于500的話顯示0
isnull函數:select isnull(a,0) from table1 選出a列,如果a列是null的話,顯示0
left join:返回左邊表所有行,right join:返回右邊表所有行,inner join:返回左右表符合要求的行
自定義函數:遍歷逗號分割的字段
create function browseid(@a NVarchar(max),@split NVarchar(10))returns @t table(c1 varchar(100))as begindeclare @i int,@s int,@aa NVarchar(max)set @aa=select nameid from bianliset @i=1set @s=1while(@i>0)beginset @i=CHARINDEX(@split,@a,@s)if(@i>0)begininsert @t(c1) values(substring(@a,@s,@i-@s))endelse begininsert @t(c1) values(substring(@a,@s,len(@a)-@s+1))endset @s=@i+1endreturnend
新聞熱點
疑難解答