SELECT DISTINCT (t.model_id), COUNT( t.int_level ) AS count_1, t.int_level, m.name
FROM tbl_event t, model m
WHERE t.model_id = m.model_id
GROUP BY model_id, int_level
model_id รุ่นรถ
int_level ระดับความสนใจ
name ชื่อรุ่นรถ
SELECT m.name, SUM(CASE int_level WHEN 1 THEN 1 ELSE 0 END ) AS cold,
SUM(CASE int_level WHEN 2 THEN 1 ELSE 0 END ) AS warm,
SUM(CASE int_level WHEN 3 THEN 1 ELSE 0 END ) AS hot,
SUM(CASE int_level WHEN 4 THEN 1 ELSE 0 END ) AS veryhot,
COUNT( * ) AS total
FROM tbl_event t, model m
WHERE t.model_id = m.model_id
GROUP BY m.name