silviadana
New member
- Local time
- Today, 05:29
- Joined
- Mar 9, 2010
- Messages
- 7
I have problems with subquerys, in fact I don't know how to avoid using the same condition in the query and subquery.
For example, i have the table
I need to find out in which of the last five years were purchased the most cars??
I want to avoid using the same condition
For example, i have the table
Code:
cars(Carnumber,DateofAcquisition)
I need to find out in which of the last five years were purchased the most cars??
Code:
SELECT YEAR(DateofAcquisition), COUNT(CarNumber)
FROM cars
WHERE YEAR(dateofAcquisition)>=YEAR(Date())-5
GROUP BY YEAR(DateofAcquisition)
HAVING COUNT(CarNumber)>=ALL (SELECT COUNT(carNumber)
FROM cars
WHERE YEAR(DateofAcquisition)>=YEAR(date())-5)
GROUP BY YEAR(DateofAcquisition))
I want to avoid using the same condition
Code:
WHERE YEAR(dateofAcquisition)>=YEAR(Date())-5