IanStrange
Programmer
Hi
Where I work uses sql server however we have some legacy systems on Oracle and I am not that familiar with the writting of queries.
I have to make and example up as my boss does not wish for me to give away any system info.
ok
table 1 (car usage)
salesmanid, year, carid
table 2 (type of car)
carid, cardesc
we need to see which sales man has used over 6 different cars in 1 year and the car desc of each of these cars.
I have tried using a subquery but have got every car he has ever used.
this was the query
SELECT dbo.car_usage.salesmanid, dbo.car_usage.car_id, dbo.car.description
FROM dbo.car_usage INNER JOIN
dbo.car ON dbo.car_usage.car_id = dbo.car.car_id
WHERE (dbo.car_usage.salesmanid IN
(SELECT dbo.car_usage.salesmanid FROM dbo.car_usage
GROUP BY dbo.car_usage.salesmanid,dbo.car_usage.[year]
HAVING (COUNT(dbo.car_usage.car_id) > 6)))
ORDER BY dbo.car_usage.salesmanid
thanks for any help
Ian
No man is an island but 6 tied together make quite a good raft.
Where I work uses sql server however we have some legacy systems on Oracle and I am not that familiar with the writting of queries.
I have to make and example up as my boss does not wish for me to give away any system info.
ok
table 1 (car usage)
salesmanid, year, carid
table 2 (type of car)
carid, cardesc
we need to see which sales man has used over 6 different cars in 1 year and the car desc of each of these cars.
I have tried using a subquery but have got every car he has ever used.
this was the query
SELECT dbo.car_usage.salesmanid, dbo.car_usage.car_id, dbo.car.description
FROM dbo.car_usage INNER JOIN
dbo.car ON dbo.car_usage.car_id = dbo.car.car_id
WHERE (dbo.car_usage.salesmanid IN
(SELECT dbo.car_usage.salesmanid FROM dbo.car_usage
GROUP BY dbo.car_usage.salesmanid,dbo.car_usage.[year]
HAVING (COUNT(dbo.car_usage.car_id) > 6)))
ORDER BY dbo.car_usage.salesmanid
thanks for any help
Ian
No man is an island but 6 tied together make quite a good raft.