Question: I have two SQL tables: cars and lap\_times. 

```
cars: 
- car_id
- engine_size
- car_type

lap_times
- lap_time_id
- time
- car_id

```

i want to get the following: 
- number of cars per car\_type
- average engine size per car\_type
- fastest lap among all cars in each car\_type

I have this: 

```
SELECT 
    COUNT(cars.car_id), 
    AVG(cars.engine_size), 
    lps.FASTEST_LAP 
FROM 
    cars, 
    (SELECT lap_times.car_id AS C_ID, MIN(lap_times.time) AS FASTEST_LAP FROM lap_times) as lps 
WHERE 
    cars.car_id = lps.C_ID 
GROUP BY 
    cars.car_type

```

But I'm not getting anything. I don't get an error, though. Any ideas what's wrong?

Answer: 
try the following : 

```
SELECT cars.car_type,
       COUNT(cars.car_id),
       AVG(cars.engine_size),
       MIN(lps.FASTEST_LAP)
  FROM cars,
       lap_times
 WHERE cars.car_id = lps.C_ID
 GROUP BY cars.car_type

```
Never mind. Fixed it by grouping inside the subquery. 

```
SELECT  
    COUNT(cars.car_id),  
    AVG(cars.engine_size),  
    lps.FASTEST_LAP  
FROM  
    cars,  
    (SELECT lap_times.car_id AS C_ID, MIN(lap_times.time) AS FASTEST_LAP FROM lap_times GROUP BY lap_times.car_id) as lps
WHERE  
    cars.car_id = lps.C_ID  
GROUP BY  
    cars.car_type 

```