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 |
|
kknbrao
Starting Member
2 Posts |
Posted - 2009-02-18 : 00:49:31
|
| Hi,I have one table like followsTable Name -sourceTableColumn name and datatype like followsdate datetimecase varchar(50)price doubleactual data like followsdate,case,price1-jan-2008,a1,10.001-jan-2008,a2,20.002-jan-2008,b1,30.001-jan-2008,b4,40.002-jan-2008,b3,15.002-jan-2008,a1,12.002-jan-2008,b1,13.00now i divided as some gropus like followsgroup1 can contains a1,a2,a3,a4group2 can contains b1, b2, b3 ,b4problemi want records from both groups (group1 & group2). but it should have atleast one record in both groups in a day |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-02-18 : 02:01:24
|
| [code]SELECT sdateFROM(SELECT *,CASE WHEN [case] in ('a1','a2','a3','a4') then 'group1' WHEN [case] in ('b1', 'b2', 'b3' ,'b4') then 'group2' END AS GroupingFROM sourceTable)tGROUP BY sdateHAVING SUM(case when Grouping = 'Group1' THEN 1 ELSE 0 END) >0AND SUM(case when Grouping = 'Group2' THEN 1 ELSE 0 END) >0[/code] |
 |
|
|
kknbrao
Starting Member
2 Posts |
Posted - 2009-02-18 : 02:11:19
|
| thanks for your solution but i want like followsthe following records only should produce2-jan-2008,b1,30.002-jan-2008,a1,12.00every date should contain atleast one record for every group. |
 |
|
|
|
|
|
|
|