SQL別名相加

2022-12-07 17:56:16 字數 572 閱讀 3842

1樓:

select distinct a1.a1,a1.a2,a2.b2 as 列1,

a3.c3 as 列2,

(a2.b2 + a3.c3) as 列3from a a1,

(select distinct b2 from b where a.a1=b.a1) a2,

(select distinct c2 from c where a.a1=c.a1) a3

這樣速度稍微快點,效率高點

2樓:獨駕舟千里去

select distinct a.a1,a.a2,(select distinct b2 from b where a.a1=b.a1) as 列1,

(select distinct c2 from c where a.a1=c.a1) as 列2,

((select distinct b2 from b where a.a1=b.a1)+(select distinct c2 from c where a.

a1=c.a1)) 列3

from a

只能這樣

sql起別名時不用as會加快效率嗎

select top 5 from select from table1 as vtable where vtable.id select max id from select top 50 id from select from table1 as vtable3 order by id as v...

如何用sql給資料庫中的列起別名

我給你舉個bai例子 你有表dustudent 裡面有 id,zhiname,class三列,select id as studentid name as studentname class as studentclass from student a 我分別給三列用daoas取了版 別名,表也取了...

sql裡面一表中有個類別名稱,裡面的類別分很多級別,我想求出二級類別一下的彙總,該怎麼寫啊

你的表結構呢?請列出表結構與資料,帶條件彙總可使用group by xx 建議補充一些資料 並給出你的預期結果 group by 一級類別 一張表裡有一級選單id和二級選單id,怎麼寫sql語句按照級別分類 這是極不規範的表處理,起碼增加一個關聯項指明其父子級關聯關係。而不應該用 100 200 1...