如何将这两个数据合并在一起得到这样的数据
SELECT A.schlvl AS School, COUNT(DISTINCT A.name) AS NoOfChild ,SUM(B.cat_id=1) AS Picture
FROM child AS A INNER JOIN
question AS B
ON A.child_id=B.child_id
WHERE B.answer=0 AND B.cat_id=1
GROUP BY A.schlvl
SELECT COUNT(DISTINCT A.name) AS Gotitright ,SUM(B.cat_id=2) AS Letters
FROM child AS A INNER JOIN
question AS B
ON A.child_id=B.child_id
WHERE B.answer = 0 AND B.cat_id = 2
GROUP BY A.schlvl
或者
像这样的事,但我被这个困住了
SELECT A.schlvl AS School, COUNT(DISTINCT A.name WHERE B.answer=0 AND B.cat_id=1) AS Picture , COUNT(DISTINCT A.name WHERE B.answer=0 AND B.cat_id=2) AS Letters
FROM child AS A INNER JOIN
question AS B
ON A.child_id=B.child_id
GROUP BY A.schlvl
1条答案
按热度按时间cwdobuhd1#
从你的询问中。
你可以试着用
IN
在B.cat_id
得到cat_id
1
或者2
在WHERE
条款。使用聚合函数条件let
CASE WHEN
在SUM
功能。