将记录分组的MySQL查询

将记录分组的MySQL查询,mysql,Mysql,我有这张桌子[表一] cid |到达|到达日期| [到达]字段的值可以是[T]或[F],该值为[F]。到达日期字段为空 1条记录最多只能出现2条(1条记录表示到达=T,另一条记录表示到达=F),但也有一些记录可能只出现一次 1 | T | 2012-02-01 2 | F | [Null] 1 | F | [Null] 3 | T | 2012-03-05 我需要一个查询来显示类似的内容 cid | arrived | not_arrived 1 Yes Yes 2

我有这张桌子[表一]

cid |到达|到达日期|

[到达]字段的值可以是[T]或[F],该值为[F]。到达日期字段为空

1条记录最多只能出现2条(1条记录表示到达=T,另一条记录表示到达=F),但也有一些记录可能只出现一次

1 | T | 2012-02-01
2 | F | [Null]
1 | F | [Null]
3 | T | 2012-03-05
我需要一个查询来显示类似的内容

cid | arrived | not_arrived
1      Yes          Yes
2      No           Yes
3      Yes          No
这项工作:

SELECT
    cid,
    SUM(arrived = 'T') > 0 as arrived,
    SUM(arrived = 'F') > 0 as not_arrived 
FROM [Table 1]
GROUP BY cid;
你可以在这里试试:

试试

select cid, 
   case when find_in_set('T', group_concat(arrived)) > 0 then 'yes'  else 'no' end as arrived, 
   case when find_in_set('F', group_concat(arrived)) > 0 then 'yes'  else 'no' end as not_arrived
from table1
group by cid