我的查询
SELECT COUNT(DISTINCT alloc.[code4]) AS countcode4,code4, table2.itemid as tbitemid2
FROM table1,table 2
WHERE table1.id=table2.id
GROUP BY code4, tbitemid2
我希望查询给我计数并仅返回'code4'的一个实例
我该怎么做?
由于 Mithil
答案 0 :(得分:0)
删除code4] from the
组by,并使用聚合函数:
SELECT COUNT(DISTINCT alloc.[code4]) AS countcode4, min(code4) as code4,
table2.itemid as tbitemid2
FROM table1 join
table2
on table1.id = table2.id
GROUP BY tbitemid2;
我不知道alloc
是什么;它来自您的示例查询。