同じ日付(count(TransactionDate)> 1)の複数のトランザクションを持つ従業員のみを返すSQLクエリを作成しようとしていますが、トランザクションは異なるストアIDで発生しています。私はカウントの集約と持っている組み合わせを使用しようとしていますが、正しい値を返すように見えません。一時テーブルを使用する方が良いでしょうか、それともサブクエリでしょうか?私の下の質問は正確な記録を返さない。どんな助けもありがとうございます。ありがとう!複数の条件を持つSQL Count集計
EmployeeID | StoreID | TransactionDate
--------------------------------------
1 | 1 | 2016-09-09 --should be returned
--------------------------------------
1 | 2 | 2016-09-09 --should be returned
--------------------------------------
1 | 3 | 2016-09-09 --should be returned
--------------------------------------
1 | 1 | 2016-09-18 --should not be returned
--------------------------------------
2 | 1 | 2016-09-09 --should not be returned
--------------------------------------
2 | 1 | 2016-09-09 --should not be returned
--------------------------------------
3 | 1 | 2016-09-09 --should not be returned
--------------------------------------
4 | 5 | 2016-09-09 --should be returned
--------------------------------------
4 | 6 | 2016-09-09 --should be returned
select top 1000 EmployeeID, StoreID, TransactionDate, count(StoreID)[StoreCount], count(TransactionDate)[Transaction Count]
from myTable
group by EmployeeID, StoreID, TransactionDate
having count(StoreID) > 1 and count(TransactionDate) > 1
order by TransactionDate desc
どのrdbms? sql-sever、mysql、oracle、...?これは窓関数のための完全な例であるので、違いを生みます – Matt