Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
为您的 SQL 专家提供的简单 SQL。
我有两个字段(AccountNo,CheckNo)。可以有超过 1 个具有相同值的 checkno。它将具有相同的 AccountNo。我想从 mytable 中列出一个显示 AccountNo 和 CheckNo 的列表,就像它存在的次数一样。
Select Distinct AccountNo, CheckNo, Count(Distinct AccountNo, CheckNo) as Total from MyTable
你追求的是GROUP BY
GROUP BY
Select AccountNo, CheckNo, Count(*) as Total from MyTable group by AccountNo, CheckNo