积极答复者
初学者求SQL代码怎么写,仅需几行而已

问题
答案
-
你好,
你也可以参考下面的代码。
;WITH CTE AS ( SELECT * , COUNT(1) OVER (PARTITION BY [交易日期], [客户名称], [交易柜员]) AS [cnt] FROM table1 ) SELECT * FROM CTE WHERE [cnt] > 5
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
全部回复
-
create table #t ( tdate datetime, account varchar(100), counter varchar(100) ) insert into #t select '2017-4-1','A1','C1' UNION ALL select '2017-4-1','A1','C1' UNION ALL select '2017-4-1','A1','C1' UNION ALL select '2017-4-2','A1','C1' UNION ALL select '2017-4-2','A1','C1' UNION ALL select '2017-4-3','A1','C1' UNION ALL select '2017-4-3','A1','C1' UNION ALL select '2017-4-3','A1','C1' UNION ALL select '2017-4-3','A1','C1' UNION ALL select '2017-4-3','A1','C1' UNION ALL select '2017-4-3','A1','C1' UNION ALL select '2017-4-3','A1','C1' select * from #t t1,( select tdate,account,counter,count(*) as cnt from #t group by tdate,account,counter having count(*)>5 ) t2 where t1.account=t2.account and t1.counter=t2.counter and t1.tdate=t2.tdate
family as water
-
你好,
你也可以参考下面的代码。
;WITH CTE AS ( SELECT * , COUNT(1) OVER (PARTITION BY [交易日期], [客户名称], [交易柜员]) AS [cnt] FROM table1 ) SELECT * FROM CTE WHERE [cnt] > 5
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.