SqlServer 基礎(chǔ)知識 數(shù)據(jù)檢索、查詢排序語句
更新時間:2011年10月25日 14:59:53 作者:
SqlServer 基礎(chǔ)知識 數(shù)據(jù)檢索、查詢排序語句,需要的朋友可以參考下。
復制代碼 代碼如下:
--執(zhí)行順序 From Where Select
select * from
(select sal as salary,comm as commission from emp ) x where salary<5000
--得出 Name Work as a Job
select ename +' Work as a'+job as msg from emp where deptno=10
--如果員工工資小于2000返回UnderPaid 大于等于4k 返回OverPaid 之間返回OK
select ename,sal,
case when sal<2000 then 'UnderPaid'
when sal>=4000 then 'OverPaid'
else
'OK'
end
from emp
--從表中隨機返回N條記錄 newid()
--order by 字句中指定數(shù)字常量時,是要求根據(jù)select列表中相應位置的列排序
--order by 字句中用函數(shù)時,則按函數(shù)在沒一行計算結(jié)果排序
select top 5 ename from emp order by newid()
--找空值is null
select * from emp where comm is null
--將空值轉(zhuǎn)換為實際值
--解釋:返回其參數(shù)中第一個非空表達式
--coalesce 聯(lián)合,合并,結(jié)合.英音:[,kəuə'les]美音:[,koə'lɛs]
select coalesce(comm, 1),empNo from emp
--按模式搜索
--返回匹配特定子串或模式的行
select ename,job
from emp
where deptno in(10,20)
--按子串排序 按照職位字段的 最后兩個字符排序
select ename, job from emp order by substring(job,len(job)-2,2)
--select top 2 len(job)-2 from emp
--select top 2 job from emp
--☆☆☆☆☆處理排序空值☆☆☆☆☆ [只能是大于0]
select ename ,sal,comm
from emp
order by 1 desc
-- 以降序或升序方式排序非空值,將空值放到最后,可以用case
select ename,sal,comm from
(
select ename ,sal,comm ,
case when comm is null then 0 else 1 end as A
from emp
) x
order by A desc ,comm desc
相關(guān)文章
sql server 自定義分割月功能詳解及實現(xiàn)代碼
這篇文章主要介紹了sql server 自定義分割月功能詳解及實現(xiàn)代碼的相關(guān)資料,需要的朋友可以參考下2016-10-10解決無法在unicode和非unicode字符串數(shù)據(jù)類型之間轉(zhuǎn)換的方法詳解
本篇文章是對無法在unicode和非unicode字符串數(shù)據(jù)類型之間轉(zhuǎn)換的解決方法進行了詳細的分析介紹,需要的朋友參考下2013-06-06SQL Server 開窗函數(shù) Over()代替游標的使用詳解
這篇文章主要介紹了SQL Server 開窗函數(shù) Over()代替游標的使用,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-10-10用戶"sa"登陸失敗 SQLServer 錯誤18456的解決方法
sqlserver下用sa登錄提示18456錯誤的解決方法。2009-11-11SQL語句執(zhí)行超時引發(fā)網(wǎng)站首頁訪問故障問題
由于獲取網(wǎng)站首頁列表的 SQL 語句出現(xiàn)突發(fā)的查詢超時問題,造成訪問網(wǎng)站首頁時出現(xiàn) 500 錯誤,在故障期間記錄了大量錯誤,小編給大家分享到腳本之家平臺,感興趣的朋友一起看看吧2020-02-02windows11安裝sqlserver?2016數(shù)據(jù)庫報錯等待數(shù)據(jù)庫引擎恢復句柄失敗解決辦法
最近安裝SQL?Server遇到這個問題,試過網(wǎng)上幾乎所有辦法,都安裝不上,查了很久才解決,下面這篇文章主要給大家介紹了關(guān)于windows11安裝SQL?server數(shù)據(jù)庫報錯等待數(shù)據(jù)庫引擎恢復句柄失敗的解決辦法,需要的朋友可以參考下2023-06-06