我的查询有效,看起来像这样:
SELECT
SUM(`WTE`) / 1000 AS WTE
FROM `orthoptists` AS o
LEFT JOIN `instances` AS i
ON o.instance_FK = i.id
WHERE i.region = 14 AND o.band = "D" AND o.age = "A" ;
对于o.band和o.age,我有10个可能的值,我需要对这两个值的每个排列进行此查询的结果。
我对SQL很新:有没有办法使用子查询来生成o.band中的一个值的所有结果(比方说)?或者甚至可以一次性完成所有工作?
性能并不重要:便利性。
答案 0 :(得分:2)
试试这个
SELECT
SUM(`WTE`) / 1000 AS WTE, o.band, o.age
FROM `orthoptists` AS o
LEFT JOIN `instances` AS i
ON o.instance_FK = i.id
WHERE i.region = 14
group by o.band, o.age