SELECT
NAME,
IF(LOCATE(1, GROUP_CONCAT(STATUS)) != 0 AND LOCATE(2, GROUP_CONCAT(STATUS)) != 0,"true","false")
FROM
test
GROUP BY
NAME
select name,flag=count(1) from #tt where status in (1,2) group by name
这样的结果就会没有flag=0的字段
或者这样就有0的数据
select name,flag=(select count(1) from #tt where name=a.name and status in (1,2)) from #tt a group by name
貌似不行。。。
@我恰芙蓉王: 我用的是Sql Server,也不至于mysql 不行吧
SELECT NAME, COUNT(1) AS flag
FROM test
WHERE STATUS IN(1,2)
GROUP BY NAME
HAVING COUNT(1)=2
。。。。
select DISTINCT name, '1' as flag from test where status = 1 or status = 2