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 |
Leigh79
Starting Member
28 Posts |
Posted - 2008-03-12 : 07:55:10
|
Hi GuysCan you help me with this? I am trying to find out the percentage each row's commission is of the total commission.My Query is:SELECT tbl1.tar_seasoncode, SUM(tbl1.tar_opcommoninvoice), SUM(tbl1.tar_opcommoninvoice)/SUM(tbl2.tot)FROM tar_downloads_new AS tbl1, ( SELECT SUM(tar_opcommoninvoice) AS tot FROM tar_downloads_new WHERE (tar_download_filename LIKE '%BA733436%') ) tbl2 WHERE (tar_download_filename LIKE '%BA733436%')GROUP BY tar_seasoncodeThe error message I am getting is - Column 'tbl2.tot' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.Where am I going wrong?Thanks |
|
Leigh79
Starting Member
28 Posts |
Posted - 2008-03-12 : 08:08:03
|
Sorry, I've just realised what an idiot I've been, I have now added 'tbl2.tot' into the GROUP Clause!! |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-03-12 : 08:10:34
|
[code]DECLARE @Sample TABLE (t INT, v INT)INSERT @SampleSELECT 1, 1 UNION ALLSELECT 1, 2 UNION ALLSELECT 2, 1 UNION ALLSELECT 3, 4SELECT x.t, x.v, 100.0 * x.v / p.vFROM ( SELECT t, SUM(v) AS v FROM @Sample GROUP BY t ) AS xCROSS JOIN ( SELECT SUM(v) AS v FROM @Sample ) AS p[/code] E 12°55'05.25"N 56°04'39.16" |
 |
|
|
|
|
|
|