+ 1
Sql question (homework 2)
Greetings, I hope teach don't mind I'm surfing In the Internet in search for an answer. I have a list of cars in which I also have the number(N°) of company to which they belong. How do I sort companies by decreasing number of cars belonging to it? So far my code looks like : SELECT Company.nom, COUNT (Car.num) FROM Cars, Company WHERE Company.num = Car.numCompany GROUP BY Company.nom; I would really appreciate your help, thanks.
6 Answers
+ 3
add this code after
GROUP BY clause
ORDER BY company.nom DSEC
+ 3
SELECT Company.Num,Cars.Num,Count(Cars.Num) as CountOfCars FROM Company
INNER JOIN Cars
ON Cars.Num=Company.Num
GROUP BY Company.Num
ORDER BY CountOfCars DSEC
I think this was true
+ 3
select d.dname, e.deptno,count (e.empno)
from emp e, dept d
where e.deptno=d.deptno
group by e.deptno,d.dname
order by (count(e.empno)) ;
it is working SQL on emp and dept table
+ 2
you should use nested queries
+ 1
^ I tried it before, but my task is to sort them by number of cars they currently have. from company with the biggest amount of cars, to the company with the smallest amount.
+ 1
Nope, didn't work. I guess you require more info to make this work than I've already gave. Thanks anyway, I guess just gonna ask teacher next Friday.