此查询为我提供了年龄和国家/地区的人数结果。下面是我需要的图片。就像一个Pivot表。
SELECT count(age) AS numberofpeople, age, country
FROM (
SELECT person_id,
TIMESTAMPDIFF(256,CHAR(TIMESTAMP(a.admission_date) - TIMESTAMP(p.dateofbirth))) AS Age,
dateofbirth,
a.admission_date
FROM person p
LEFT JOIN admission a ON p.person_id = a.person_id
WHERE category = '1'
AND startdate BETWEEN '8/1/2016' AND '10/31/2017') AS a
WHERE age <= '10'
GROUP BY country, age
谢谢