MySQL将两个记录合并为一个(MySQL merge two records into one)

编程入门 行业动态 更新时间:2024-10-28 05:19:05
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 status

now 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 1

How 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`

更多推荐

本文发布于:2023-08-07 03:40:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1461155.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:并为   两个   MySQL   merge   records

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!