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 - 2011-10-06 : 23:13:05
|
| Need help with the below example Sample DataIdenret Sourcesys Customerid revivaldt1 mbill 123456 01/01/20102 cbill 123456 01/01/20103 mbill 987654 01/01/20104 cbill 987654 01/02/20105 cbill 654321 01/01/20106 mbill 654321 01/01/20107 cbill 975310 12/31/20108 cbill 124578 12/31/20109 mbill 975310 12/31/201010 mbill 124578 12/12/201111 cbill 888888 1/1/2011I have to retreive all the customerids from the above table where a customerid has to be part of mbill and cbill and also have the samerevivaldtso The query should returnIdenret Sourcesys Customerid revivaldt1 mbill 123456 01/01/20102 cbill 123456 01/01/20105 cbill 654321 01/01/20106 mbill 654321 01/01/20107 cbill 975310 12/31/20109 mbill 975310 12/31/2010Thanks in advance |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2011-10-06 : 23:23:33
|
[code]select d.*from ( select Customerid, revivaldt from sample_data group by Customerid, revivaldt having min (Sourcesys) = 'cbill' and max (Sourcesys) = 'mbill' ) a inner join sample_data d on a.Customerid = d.Customerid and a.revivaldt = d.revivaldtorder by d.Idenret[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-07 : 01:28:24
|
| [code]select Idenret, Sourcesys, Customerid, revivaldtfrom(select Idenret, Sourcesys, Customerid, revivaldt,count(case when Sourcesys ='mbill' then 1 else null end) over (partition by Customerid, revivaldt) as mbillcnt,count(case when Sourcesys ='cbill' then 1 else null end) over (partition by Customerid, revivaldt) as cbillcnt)twhere mbillcnt>0and cbillcnt>0[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|
|