鍍金池/ 問答/數(shù)據(jù)庫/ sql不會(huì)啦 抱大腿

sql不會(huì)啦 抱大腿

圖片描述

290 成功的次數(shù) 6 是失敗的次數(shù)
怎樣一個(gè)sql 查出來 并且按 sid 和 api分組

要求 不用UNION,不連表

想了好久 不會(huì)來求助大神

回答
編輯回答
墨小羽

寫成兩列不就完了。。
select
sid,api,
sum(case when flag=0 then count else 0 end) count1,
sum(case when flag=1 then count else 0 end) count2
from table
group by sid,api;

2017年7月31日 20:25