sql数据库基础知识整理,常用函数及常用语法
1常用數(shù)據(jù)庫聚合函數(shù)
max()
min()
sum()
avg()
count()
2字符串處理函數(shù)
len() 與 datalength()? 區(qū)別:len是返回字符長度? datalength是返回字節(jié)長度
LTrim()? RTrim() Trim ()
isnull(@FilterStr,N'')如果時空將其替換
charindex(N';', @TmpList)返回字符串中表達式的起始位置而不是index
paitndex('%ssd%',@temp) 與charindex作用基本類似
substring(@TmpList, 1, @Index - 1)
Replace('字符串',要替換的字符','替換后的字符')
uppre和lower函數(shù)
left(,) 和 right(,)??? 取前多少個字符 和 后多少個字符
stuff (?character_expression , start , length , replaceWith_expression )替換指定位置指定長度的字符串
3數(shù)字函數(shù)
Ceiling()取整 取大?? floor() 取整 取小
abs()絕對值
round(,) 四舍五入
square() 平方
sqrt()開根號
rand() 隨機值
4日期函數(shù)
getdate() 獲取系統(tǒng)時間
dateadd(時間單位,加減的變量,日期)? 日期的加減
datediff(時間單位,日期,日期)?? 倆日期的時間差
datepart(時間單位,日期)? 取出日期中的指定部分
datename(時間單位,日期)? 與datepart功能相同
isdate()判斷是否為如期格式 返回0或1
時間單位格式
year,yy,yyyy (年份)
quarter,mm,mm(月份)
dayofyear,dy, y(第幾天)
day,dd,d(日期)
week,wk,ww(星期幾)
Hour,hh(小時)
minute,mi,n(分鐘)
second,ss,s(秒)
millisecond,ms(毫秒)
5常用數(shù)據(jù)庫語法
?over() 此函數(shù)為分析函數(shù)亦可叫開窗函數(shù)可以在后臺做一些操作 例:
ROW_NUMBER() over(Partition by 分組字段order by 排序字段) 分組排序之后生成行號
sum()over(Partition by 分組字段),比如對某列分組后進行加總
SUM,AVG,COUNT,MIN,MAX等使用OVER(PARTITION BY)語句
將返回結(jié)果過濾替換語法
case when RowNum > 1 then TotalMeasureTime else 0 end
case RowNum when >1? then? TotalMeasureTime elee 0? end
union 合并兩個查詢結(jié)果 兩個查詢結(jié)果必須有相同的列? union all 是所有結(jié)果包括重復項
轉(zhuǎn)載于:https://www.cnblogs.com/fighting2014/p/3935302.html
總結(jié)
以上是生活随笔為你收集整理的sql数据库基础知识整理,常用函数及常用语法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Mac下修改ZOC中文乱码
- 下一篇: .net中从GridView中导出数据到