我对Acccess 2013有这个SQL查询,但我想有一个额外的条件说:
WHERE CLASS = 'ECN'.
我无法找到将其集成到现有查询中的方法 - 希望有人可以给我一个提示。
SELECT m.ID, m.PN, m.CLASS, m.ZAHL, (
SELECT Count(*)
FROM Table1 AS m2
WHERE m2.PN = m.PN AND m2.ID <= m.ID
) AS IncByPN
FROM Table1 AS m
ORDER BY m.ID;
所以我希望结果表只显示
行 CLASS = 'ECN'
答案 0 :(得分:0)
尝试这样的事情:
SELECT m.ID,
m.PN,
m.CLASS,
m.ZAHL,
Count(M2.id) AS IncByPN
FROM Table1 AS m
INNER JOIN Table1 AS m2 ON m2.PN = m.PN AND m2.ID <= m.ID
WHERE m.CLASS='ECN'
GROUP BY m.ID, m.PN, m.CLASS, m.ZAHL
ORDER BY m.ID