假设我有一个包含以下内容的表:
CUS_ID A B
1 1 0
2 2 0
3 3 1
3 1 3
4 2 0
有没有办法编写一个select语句并获取所有不同的cus_id?所以基本上它只会为cus_id 3带回一条记录。
答案 0 :(得分:1)
SELECT DISTINCT CUS_ID FROM table_name;
答案 1 :(得分:0)
或者:
select
CUS_ID
-- columns below are optional and exist just to
-- help you understand for what reason 'group by' is needed
-- , count(A) cntA
-- , sum(B) sumB
from YourTable
group by
CUS_ID
order by
CUS_ID
<强> UPD 即可。我的意思是评论整行:)