Im want to query distinct and count:
SELECT DISTINCT way.vehicle, count(way.vehicle), way.id, way.created_at, way.updated_at, way.version
from waypoints as way
left join dtb_vehicle on way.vehicle = dtb_vehicle.vehicle
where (6373 * acos (cos ( radians(21.0277644)) * cos ( radians (way.latitude)) * cos (radians (way.longitude) - radians (105.8341598)) + sin (radians (21.0277644)) * sin (radians (way.latitude)))) < 20
AND dtb_vehicle.vehicle_type = 600
GROUP BY way.vehicle
HAVING count(way.vehicle) > 10
But it always show error :column "way.id" must appear in the GROUP BY clause or be used in an aggregate function.
Please help me. Thanks
way.id
is the primary key, then you only need to group by that). Btw:distinct
together withgroup by
rarely makes sense. Due to thegroup by
you only get one row pervehicle
anyway – a_horse_with_no_name