MySQL将两个记录合并为一个(MySQL merge two records into one)
我有状态表
id (primary key ) case id read status delivered status现在,我可以为具有不同值的相同案例ID创建多个记录
这里我有两行的案例ID(111)
ID case_id read_status delivered_status 1 111 1 0 2 111 0 1我如何运行查询,以便为上述案例提供一行,其读取状态和交付状态为1?
SqlFiddle
http://sqlfiddle.com/#!9/9d977e/1
I have status table with
id (primary key ) case id read status delivered statusnow I can have multiple records for same case id with different values
Here I have case ID (111) with two rows
ID case_id read_status delivered_status 1 111 1 0 2 111 0 1How can I run query so it gives one row for above case with read status and delivery status to 1 ?
SqlFiddle
http://sqlfiddle.com/#!9/9d977e/1
最满意答案
读取状态和交付状态为1
你的意思是最大值? 如果是这样的话,这就是小提琴。
小提琴
查询:
select `case_id`, max(`read_status`), max(`delivered_status`) from status group by `case_id`read status and delivery status to 1
Do you mean the max value ? If so, here is the fiddle.
Fiddle
The query :
select `case_id`, max(`read_status`), max(`delivered_status`) from status group by `case_id`更多推荐
发布评论