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 |
|
jparker
Posting Yak Master
118 Posts |
Posted - 2005-04-01 : 10:53:51
|
| I have the following statement select count(distinct s.job_id), sum(case when type = 'I' then valuegros when type = 'C' then (-1 * valuegros) else 0 end) as 'valuegros' from tblSalesInvoice s join tblEstimate e on e.job_id=s.job_idwhere e.date_fully_invoiced <= '20050228' and e.date_fully_invoiced >= '20050201'group by s.job_idwhich gives me 1 | 46632.741 | 7832.55what I want to achieve is to have 2 | 54465.29 | 27232.65with the first 2 columns being the sums of the count and sum and the third being the average i.e. column 2 / column 1Is this possible? |
|
|
jparker
Posting Yak Master
118 Posts |
Posted - 2005-04-01 : 10:57:50
|
| Worked it out for myself : -select count(distinct s.job_id), sum(case when type = 'I' then valuegros when type = 'C' then (-1 * valuegros) else 0 end) as 'valuegros', sum(case when type = 'I' then valuegros when type = 'C' then (-1 * valuegros) else 0 end) / count(distinct s.job_id) from tblSalesInvoice s join tblEstimate e on e.job_id=s.job_idwhere e.date_fully_invoiced <= '20050228' and e.date_fully_invoiced >= '20050201 |
 |
|
|
|
|
|