[英]sql How to get sum of a distinct values according to set of distincted condition query
我想獲得兩個列,其中group1具有不同的值,其中c3 = yes,而group2其中具有根據group1的sum(c2)。
c1 | c2 | c3
--------------|-----
A | 2 |yes
B | 1 |yes
A | 2 |yes
B | 1 |yes
C | 2 |no
C | 1 |no
result :
group1 | group2
---------------
A | 4
B | 2
我正在嘗試此查詢,但無法正常工作
SELECT SUM(c2) WHERE DISTINCT c1 in('A','B') and c3='yes' as 'group2' from table,
SELECT DISTINCT c1 in('A','B') as 'group1' from table
SELECT c1 as group1, SUM(c2) as group2 FROM table
WHERE c3="yes"
GROUP BY c1
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.