SQL 查詢語句(備份)

2022-01-20 08:38:50 字數 932 閱讀 4905

分組查詢

1、分組查詢後獲取分組後的前5條資料

1

select

*from (select rid = row_number() over (partition by foodparentid order

by foodparentid desc), *

from foodlibinfo) as t where rid <=

5

view code

2、分組查詢後隨機獲取每一組的5條資料

1

select

*from (select rid = row_number() over (partition by foodparentid order

bynewid()), *

from foodlibinfo) as t where rid <=

5

view code

排名查詢:

1、使用row_number()函式,分數相同按照id公升序排名

1

select id,result,row_number() over (order

by result desc,id asc) as rowid from answer group

by q_user_id,q_result

view code

2、分數相同的排名相同

select

a.id,a.result,

place

=(select

count(result) from answer where result>a.result )+

1from answer a where

order

by place

view code

可能有用的:

SQL備份語句

sql備份語句 完整備份 backup database northwindcs to disk g backup northwindcs full 20070908.bak 差異備份 backup database northwindcs to disk g backup northwindcs ...

SQL Server log備份SQL語句

完全備份 backup database demo to nwdevice02 with name fullbak 日誌備份 backup log demo to nwdevice02 with name log1 restore full backup restore database demo ...

sql 語句 查詢

例11 1 1 use xk gocreate trigger test1 on student for update as print 記錄已修改!go 2 update student set pwd 11111111 where stuno 00000001 例11 3 1 use xk go...