Reputation: 4999
I have two tables:
depart
debt city
43 odesa
23 kiev
79 kiev
78 donezk
and
empl
ide fn ln debt
3421 jed trt 43
354 jed res 43
43 ged hjkhg 79
73 ghghg gfgf 79
456 jkl gdfg 78
532 kkhg vjv 23
45 ki vt 79
243 ki vt 78
I need choose rows number of employees (fn
) of each department (debt
) and sort them by city. I wrote this code:
select empl.DEBT, count (*) as emp_num
from depart
inner join empl on empl.DEBT = depart.DEBT
group by empl.DEBT
order by depart.CITY;
But this code doesn't work. What do I do wrong?
I use Oracle db, execute script in Toad.
Error message is
The following error has occurred: ORA-00900: invalid SQL statement
Upvotes: 1
Views: 347
Reputation: 4192
select empl.DEBT, count (*) as emp_num
from depart
inner join empl on empl.DEBT = depart.DEBT
group by depart.CITY,empl.DEBT
order by depart.CITY;
Upvotes: 1
Reputation: 70678
For you to order by city, then you also need to group by city:
select empl.DEBT, count (*) as emp_num
from depart
inner join empl
on empl.DEBT = depart.DEBT
group by empl.DEBT, depart.CITY
order by depart.CITY;
Upvotes: 2