我有以下查询:
SELECT c.danhoEstetico, c.danhoDirecto
FROM conceptos c
INNER JOIN materialesconceptos mc ON mc.idConcepto = c.idConcepto
INNER JOIN materiales m ON m.idMaterial = mc.idMaterial
WHERE m.idMaterial IN (4,11,11)
这会产生以下结果(例如):
danhoEstetico | danhoDirecto
1 | 0
1 | 0
0 | 0
0 | 0
我需要做一个查询,如果每列中的任何项目都有一个 1,比如同一列中所有字段之间的 OR,输出如下:
danhoEstetico | danhoDirecto
1 | 0
我试过了:
SELECT
SUM(CASE c.danhoEstetico WHEN c.danhoEstetico=1 THEN 1 ELSE 0 END) AS de,
SUM(CASE c.danhoDirecto WHEN c.danhoDirecto=1 THEN 1 ELSE 0 END) AS dd
FROM conceptos c INNER JOIN materialesconceptos mc ON mc.idConcepto = c.idConcepto
INNER JOIN materiales m ON m.idMaterial = mc.idMaterial
WHERE m.idMaterial IN (4,11,11)
出于某种原因,这会产生:
danhoEstetico | danhoDirecto
4 | 4
对此有任何提示吗?