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 |
|
jprogrammer
Starting Member
2 Posts |
Posted - 2008-12-12 : 11:02:24
|
Please check below tables I am trying to get number of states and districts using this querySelect c.chcountrycode, count(s.chstatecode) as states, count(d.chdistrictcode) as districtsFrom Country Cinner join Countrystatelist CS on c.chCountrycode = c.chCountrycodeinner join table_statelist sl on cs.statelistid = sl.statelistidinner join table_state s on s.chstatecode = sl.chstatecodeinner join statedistrictlist sdl on sdl.chstatecode = s.chstatecodeinner join table_districtlist dl on dl.districtlistid = sdl.districtlistidinner join table_district d on d.chdistrictcode = dl.chdistrictcodeGroup by c.chcountrycodeBut i am getting the result set likethiscountrycode-states - districtsUS 3 3Actually i got 3 districts and 2 states in the database.Please help me to write this query.Thanks in advance. |
|
|
sodeep
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2008-12-12 : 11:29:16
|
quote: Originally posted by jprogrammer Please check below tables I am trying to get number of states and districts using this querySelect c.chcountrycode, count(distinct s.chstatecode) as states, count(d.chdistrictcode) as districtsFrom Country Cinner join Countrystatelist CS on c.chCountrycode = c.chCountrycodeinner join table_statelist sl on cs.statelistid = sl.statelistidinner join table_state s on s.chstatecode = sl.chstatecodeinner join statedistrictlist sdl on sdl.chstatecode = s.chstatecodeinner join table_districtlist dl on dl.districtlistid = sdl.districtlistidinner join table_district d on d.chdistrictcode = dl.chdistrictcodeGroup by c.chcountrycodeBut i am getting the result set likethiscountrycode-states - districtsUS 3 3Actually i got 3 districts and 2 states in the database.Please help me to write this query.Thanks in advance.
|
 |
|
|
jprogrammer
Starting Member
2 Posts |
Posted - 2008-12-12 : 17:39:00
|
| Hi sodeep,Thanks alot. It is working now.Thanks for your great help.Regards,JP |
 |
|
|
|
|
|