一條SQL語句研究

2021-04-18 14:29:41 字數 845 閱讀 2399

現有「select * from t where a in (5,3,2,1,8,9,30...)" 假設 a 是主鍵,in裡面的引數是唯一的。現要求輸出的結果集按照 in 提供的引數順序排序。而不是按照a本身的排序規則排序?   。

另:如果不要求使用臨時表或表變數,那麼又有什麼辦法實現。?

臨時表方案參卡:

create table #t(id int identity(1,1),a int)

insert into #t values(5)

insert into #t values(3)

insert into #t values(2)

insert into #t values(1)

insert into #t values(8)

insert into #t values(9)

insert into #t values(30)

select t.* from t,#t as t1 where t.a=t1.a order by t1.id

select * from t where a=5 union all

select * from t where a=3 union all

select * from t where a=2 union all

select * from t where a=1 union all

select * from t where a=8 union all

select * from t where a=9 union all

select * from t where a=30

sql語句ding 求一條sql語句

我理解你的問題是每乙個使用者id在乙個部門中所有的許可權,你給的資料好像不詳細,我新增了一些資料,你看看滿足需求不。sql with authority as 2 select 3029 kuid,205 krid,21 kdid from dual union all 3 select 3029 ...

一條sql 語句的優化

第二個版本 一條sql搞定,使用巢狀查詢,費時2 3分鐘 select a.indexid,c.title,c.createdtime,c.intro,d.picurl,e.src,e.size,e.info from mms content index a,mms index node b,mms...

2 2 執行一條SQL語句

對資料庫執行一條sql語句 1 mixed mysqli query mysqli link,string query,int resultmode mysqli store result 1 對於insert,update,delete等不會返回資料的sql語句,在執行沒有錯誤時返回true 2 ...