| Author |
Topic |
|
IainMaclean
Starting Member
9 Posts |
Posted - 2009-08-17 : 22:14:58
|
| Hope you can help me.This querySelect Sum(remn_am)as Total_Remuneration, Jurisdiction, orgn_id as OrganisationFrom dbo.iamestab EstablishmentsLeft Outer join dbo.Address Addresses On establishments.residential_address_id = Addresses.adr_idLeft Outer Join dbo.tblQRegion PostCodeRegions On ltrim(rtrim(addresses.post_cd)) = ltrim(rtrim(PostCodeRegions.post_code))where orgn_id in (6818982,4934392,2694595,12672918)Group By Orgn_id, JurisdictionGives me the following resultsTotal_Remuneration, Jurisdiction, Organisation9265700.00 1_MLBN 269459588497712.00 1_MLBN 4934392552855319.00 1_MLBN 6818982113170405.00 1_MLBN 126729182025949.00 2_KNX 26945954151006.00 2_KNX 4934392131882373.00 2_KNX 681898271069211.00 2_KNX 126729181694823.00 3_GLNG 26945955816064.00 3_GLNG 493439299082310.00 3_GLNG 681898257078878.00 3_GLNG 126729181075561.00 4_BGO 2694595674358.00 4_BGO 493439251079257.00 4_BGO 681898218182754.00 4_BGO 126729182090586.00 5_SPN 2694595278132.00 5_SPN 493439214736525.00 5_SPN 68189829244206.00 5_SPN 126729181125198.00 6_ALBY 2694595193039.00 6_ALBY 493439223351836.00 6_ALBY 681898211160545.00 6_ALBY 12672918169007.00 7_MLDA 49343929182427.00 7_MLDA 68189825544298.00 7_MLDA 12672918What i really want to be able to do is select only the Jurisdiction which has the highest Total_Remuneration. Eliminating duplicated organisations.I suspect i need to do a subquery of some kind. Any advice would be appreciated. |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
|
|
IainMaclean
Starting Member
9 Posts |
Posted - 2009-08-17 : 22:27:46
|
| Sorry should have said, has to be accommodated by SQL 2000 for now. |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-08-17 : 22:52:22
|
[code]Select Sum(remn_am)as Total_Remuneration, Jurisdiction, orgn_id as OrganisationFrom dbo.iamestab Establishments Left Outer join dbo.Address Addresses On establishments.residential_address_id = Addresses.adr_id Left Outer Join dbo.tblQRegion PostCodeRegions On ltrim(rtrim(addresses.post_cd)) = ltrim(rtrim(PostCodeRegions.post_code))where orgn_id in (6818982,4934392,2694595,12672918)Group By Orgn_id, Jurisdiction[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
IainMaclean
Starting Member
9 Posts |
Posted - 2009-08-17 : 22:56:40
|
| Umm i need the jurisdiction with the most remuneration per organisation. Thanks for your input though. |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-08-17 : 23:21:07
|
there will be more than one jurisdiction per organization so which one do you want ? KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
IainMaclean
Starting Member
9 Posts |
Posted - 2009-08-17 : 23:35:56
|
| I want to select only the jurisdiction with the highest total remuneration value. For the following organisation i only want to select 1_MELB.552855319.00 1_MLBN 6818982131882373.00 2_KNX 681898299082310.00 3_GLNG 681898251079257.00 4_BGO 681898214736525.00 5_SPN 681898223351836.00 6_ALBY 68189829182427.00 7_MLDA 6818982the query will not be specific to 1 organisation but many. |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-08-18 : 02:27:17
|
only 1 row ? is it ?Select TOP 1 Sum(remn_am)as Total_Remuneration, Jurisdiction, orgn_id as OrganisationFrom dbo.iamestab Establishments Left Outer join dbo.Address Addresses On establishments.residential_address_id = Addresses.adr_id Left Outer Join dbo.tblQRegion PostCodeRegions On ltrim(rtrim(addresses.post_cd)) = ltrim(rtrim(PostCodeRegions.post_code))where orgn_id in (6818982,4934392,2694595,12672918)Group By Orgn_id, JurisdictionOrder By Total_Remuneration DESC KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
ra.shinde
Posting Yak Master
103 Posts |
Posted - 2009-08-18 : 02:29:21
|
| Table structures will be required.Rahul Shinde |
 |
|
|
|