Question : combe SQL query

Hi,

I have data looks like this, I need to find out d12, and d34, in this case, which will be 25 and 40, since in d12, two have same date.  for d34, 8/1 abd 7/1 have the same date, so it would be 40.  I could use a query for each number, my queston is, is there a way to combine into one query and return two numbers.  Basically, I want to hit db once instead of twice...thx
 
                      d1               d2                  d3                d4              d12           d34
10/1/2009                                        9/1/2009     9/5/2009                            5    
9/1/2009     7/5/2009  8/1/2009                                                    25
8/1/2009                                          7/10/2009   8/15/2009                          35
7/1/2009     7/5/2009   8/1/2009     7/10/2009   8/15/2009          25            35
 
Code Snippet:
1:
2:
3:
4:
5:
6:
select distinct d1,d2, sum(d12)
from mytable


select distinct d3,d4, sum(d34)
from mytable

Answer : combe SQL query

Since you use different criteria for "uniqueness" for d12 and d34, you need two selects, but you can combine them e.g. by using a UNION. I would do like this:

select d1, d2, sum(d12), null, null, null from mytable group by d1, d2
union all
select null, null, null, d3, d4, sum(d34) from mytable group by d3, d4
Random Solutions  
 
programming4us programming4us