Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with count function in SQL

Status
Not open for further replies.

RocAFella2007

Technical User
Mar 21, 2007
45
GB
Hi, im not sure if this is in the correct section. I am using oracle and have been experiencing some problems when I try to run the following query.

I want to display all car Id's which are less than 5, in the table there is alot of details.

So basically when the query runs, all the carid values get counted, and if they are less than 5 I want them to appear, I have the following so far:

SELECT CARID, COUNT(CARID)
2 FROM TAXIJOURNEY
3 WHERE COUNT(CARID) < 5
4 GROUP BY CARID;

It keeps throwing an error, could anyone please give me a suggestion? Thanks
 
SELECT CARID, COUNT(CARID)
FROM TAXIJOURNEY
GROUP BY CARID
HAVING COUNT(CARID) < 5

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks that did work, however now I am facing a problem joining tables. You see in my output I want to display all the information to do with the car, So far I have the following:

SELECT TAXIJOURNEY.CARID, CAR.CARMAKE, CAR.MODEL, CAR.REG, COUNT(TAXIJOURNEY.CARID) AS NUMBEROFCARS
FROM TAXIJOURNEY
JOIN CARDETAILS
ON TAXIJOURNEY.CARID = CARDETAILS.CARID
GROUP BY CARID
HAVING COUNT(TAXIJOURNEY.CARID) <5;

Im just not sure why it is not working, any suggestion please?
 
Hey, dont worry about it I got it fixed and its fully working.

Thanks alot for all your help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top