gpt4 book ai didi

MySQL:案例陈述问题

转载 作者:行者123 更新时间:2023-11-29 23:16:21 25 4
gpt4 key购买 nike

Complaint_status 表:投诉的多行

id  complaint_id  status_type  status_value
1 11 2 0
2 11 2 2
3 11 2 1
4 11 2 2

尝试获取具有 status_type=2status_value=2 但显示 nullmin(id),必须使用 case 语句来做其他事情。

SELECT c3.id AS Ticket_id,
CASE
WHEN cs.status_value=2 THEN cs.created_at
ELSE NULL
END AS Closure_date
FROM complaint c3
INNER JOIN complaint_status cs ON cs.complaint_id=c3.id
WHERE cs.id IN
(SELECT min(id)
FROM complaint3_status
WHERE complaint_id=c3.id
AND status_type=2)
AND c3.id IN(11)

最佳答案

这是一种为您提供整行的方法:

select cs.*
from complaint_status cs
where status_type = 2 and status_value = 2
order by id asc
limit 1;

如果您想要的话,您可以只使用select id。我不知道 case 与此查询有什么关系。

关于MySQL:案例陈述问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27761788/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com