gpt4 book ai didi

mysql - 如果在 WHERE 内

转载 作者:太空宇宙 更新时间:2023-11-03 12:22:12 24 4
gpt4 key购买 nike

我在 WHERE 子句中使用 IF() 语句编写了一个查询:

SELECT DISTINCT a.*, u.user_email, u.user_nicename, u.user_login, u.display_name
(
SELECT b.date_recorded
FROM wp_bp_activity as b
WHERE b.type IN ( 'activity_comment','activity_update' )
AND IF(b.type = 'activity_comment', b.item_id, a.id) = a.id
ORDER BY b.item_id desc
limit 0,1
) as drecord
FROM wp_bp_activity as a
LEFT JOIN wp_users as u ON a.user_id = u.ID
WHERE
a.type IN ( 'activity_update' )
order by cast(drecord as datetime) desc
limit 0,20

但它给出了错误:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT b.date_recorded FROM wp_bp_activity as b WHERE b.' at line 3

这样使用 IF 的正确方法是什么?

最佳答案

首先要更改的是在 u.display_name 之后添加逗号。它应该有所帮助。

关于mysql - 如果在 WHERE 内,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19381207/

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