SQL专家的简单SQL。
我有两个字段(AccountNo,CheckNo)。可以有多个具有相同值的checkno。它将拥有相同的AccountNo。我希望mytable显示AccountNo和CheckNo的列表,以及它存在的次数。
Select Distinct AccountNo, CheckNo, Count(Distinct AccountNo, CheckNo) as Total
from MyTable
答案 0 :(得分:10)
你所追求的是GROUP BY
Select AccountNo, CheckNo, Count(*) as Total
from MyTable
group by AccountNo, CheckNo
答案 1 :(得分:3)
Select AccountNo, CheckNo, Count(*) as Total
from MyTable
group by AccountNo, CheckNo