Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
jim_jim
Constraint Violating Yak Guru
306 Posts |
Posted - 2014-09-29 : 12:04:00
|
Hi EveryoneNeed help to eliminate certain records from my query.The below is a simple query to illustrate my problemMy QuerySelect RequestNo,Event_type from Event_log where Event_type in (10,20) DataRequestNo Event_type123456 10123457 10123457 20123458 10123459 10123459 20This above query returns all requests that meets atleast one criteria. How do i edit my query such that i get requests that meet both criteria and the result set looks like belowDataRequestNo Event_type123457 10123457 20123459 10123459 20Thanks |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2014-09-29 : 12:56:02
|
[code]; WITH cte (RequestNo, EventTypeCount)AS( SELECT RequestNo, COUNT(*) AS EventTypeCount FROM Event_log GROUP BY RequestNo HAVING COUNT(*) > 1)SELECT e.RequestNo, e.Event_typeFROM Event_log eJOIN cteON e.RequestNo = cte.RequestNo[/code]Tara KizerSQL Server MVP since 2007http://weblogs.sqlteam.com/tarad/ |
|
|
jim_jim
Constraint Violating Yak Guru
306 Posts |
Posted - 2014-10-01 : 18:20:15
|
Thanks |
|
|
|
|
|