gpt4 book ai didi

mysql条件语句?

转载 作者:太空宇宙 更新时间:2023-11-03 10:58:56 25 4
gpt4 key购买 nike

我在 sql 查询中遇到了一个小问题,

这里是查询

SELECT events.event_id,
( SELECT favorite_events.event_id,
(CASE favorite_events.event_id WHEN NULL THEN 0 ELSE 1 END)
FROM favorite_events
WHERE favorite_events.event_id = events.event_id
) AS is_favorite
FROM events
WHERE start_date = 2013-07-16

它给我“操作数应该包含 1 列"错误,请帮助!

最佳答案

使用 JOIN,而不是相关子查询。

SELECT e.event_id,
f.event_id IS NOT NULL AS is_favorite
FROM events e
LEFT JOIN favorite_events f
ON f.event_id = e.event_id
WHERE e.start_date = '2013-07-16'

关于mysql条件语句?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17672918/

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