SQL 中的 Sumifs 语句
Sumifs statement in SQL
我正在尝试在 SQL 中 sumif
并获得准确的结果,但它也显示了其他所有内容。
例如:
select brand, sum(if(channel = 'A' and brand in ('001', '002'), orderz, 0)) as conv1
from data.sumifs
where type IN ('C6', 'C4')
group by channel, brand, orderz, type;
这为我提供了品牌 001 和 002 的正确结果以及显示为 0 的所有其他内容
如何从 table 中删除这些 0 值行,并在 SQL 中使用 sum if 语句仅接收“001”和“002”的值?
添加一个 WHERE
子句来过滤结果:
...
WHERE channel = 'A'
AND brand IN ('001', '002')
...
这确实意味着您也不再真正需要 If()
!
SELECT brand
, Sum(orderz) AS conv1
FROM data.sumifs
WHERE type IN ('C6', 'C4')
AND channel = 'A'
AND brand IN ('001', '002')
GROUP
BY brand
我正在尝试在 SQL 中 sumif
并获得准确的结果,但它也显示了其他所有内容。
例如:
select brand, sum(if(channel = 'A' and brand in ('001', '002'), orderz, 0)) as conv1
from data.sumifs
where type IN ('C6', 'C4')
group by channel, brand, orderz, type;
这为我提供了品牌 001 和 002 的正确结果以及显示为 0 的所有其他内容
如何从 table 中删除这些 0 值行,并在 SQL 中使用 sum if 语句仅接收“001”和“002”的值?
添加一个 WHERE
子句来过滤结果:
...
WHERE channel = 'A'
AND brand IN ('001', '002')
...
这确实意味着您也不再真正需要 If()
!
SELECT brand
, Sum(orderz) AS conv1
FROM data.sumifs
WHERE type IN ('C6', 'C4')
AND channel = 'A'
AND brand IN ('001', '002')
GROUP
BY brand