Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Blog
Combined Where and having
create table #TempAccount (UserId int, ACID int) insert into #TempAccount values (100, 1), (100, 2), (100, 3), (100, 4), (101, 2), (102, 1), (103, 2), (103, 3), (103, 4) select * from #TempAccount Select USERID,ACID, ROW_NUMBER() over(partition by USERID order by USERID ) as rownumber into #abc from #TempAccount --WHERE rownumber < = 2 and ACID in (2,3) SELECT *,ROW_NUMBER() over(partition by USERID order by USERID ) as rownumber FROM #abc where ACID in (2,3) and having count(rownumber) >=2 --select ACID from #abc where ACID in (2,3) group by ACID HAVING COUNT(ACID) = 2 drop table #TempAccount
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
My data
a
Turn comma-separated numbers in string into rows
/Users/svetlanakanevskaa/Downloads/ACDB.sql
Cte recursion
for xml path concatenation ordered by seqno
Branch
Veterinary 1
Insert multiple parent-child records
TSQL - Unique string generator
stackse - search stackoverflow differently
Please log in to post a comment.