Sql語句收藏

2022-01-16 01:32:46 字數 672 閱讀 3122

1、 查詢列表,按照in的排序進行排序

code

select

*, (

select

count(0

) from

[picture

]where

album_id=[

album

].id) 

aspiccount 

from

[album

]where

id in(5

,6,8

,1,3

,4) order

bycharindex('

,'+ltrim

(rtrim

(str

(id))) +'

,','

,5,6,8,1,3,4,')

2、查詢不重複結果,按照另外乙個字段進行排序

code

select

distinct

a,b,

max(c)

from

table

group

bya, b

order

bymax

(c)(通常情況在,a,b為使用者id和使用者名稱,但是要按照c:新增時間來進行排序,這時候就要使用這個方法了)

陸續新增中,希望對大家有幫助~

SQL鎖表語句 收藏

sql鎖表語句 收藏 鎖定資料庫的乙個表 select from table with holdlock 注意 鎖定資料庫的乙個表的區別 select from table with holdlock 其他事務可以讀取表,但不能更新刪除 select from table with tablockx...

少用且有用的SQL語句 收藏

1.waitfor 例 等待1 小時2 分零3 秒後才執行select 語句 waitfor delay 01 02 03 select from employee 例 等到晚上11 點零8 分後才執行select 語句 waitfor time 23 08 00 select from emplo...

SQL 收藏 SQL操作全集

sql操作全集 7 d x a0d r d g0e x 下列語句部分是mssql語句,不可以在access中使用。7x k sql分類 ddl 資料定義語言 create,alter,drop,declare 9j3u i l t w r3 z dml 資料操縱語言 select,delete,up...