gpt4 book ai didi

mysql - 使用 IF 语句进行查询

转载 作者:行者123 更新时间:2023-11-29 09:00:35 25 4
gpt4 key购买 nike

我有一个关于 MYSQL If 语句的问题。我的要求:

SELECT c.status, c.thumb, j.id, j.name, j.username, s.session_id, a.time, a.isactive, a.country, a.countrycode, a.city
FROM j16_users AS j
JOIN j16_community_users AS c ON c.userid = j.id
LEFT JOIN j16_session AS s ON s.userid = j.id
LEFT JOIN j16_session AS s ON s.userid = j.id
LEFT JOIN j16_x5_fastchat_users AS a ON a.userid = j.id
WHERE j.id IN (62,66,2692)

如何添加新列:带有条件的 isonline 到上述请求:

IF(a.time > DATE_SUB(NOW(), INTERVAL 1 MINUTE), "1", "0") AS isonline

谢谢!

最佳答案

SELECT c.status, c.thumb, 
j.id, j.name,
j.username, s.session_id,
a.time, a.isactive,
a.country, a.countrycode, a.city,
IF(a.time > DATE_SUB(NOW(), INTERVAL 1 MINUTE), 1, 0) AS isOnline
FROM j16_users AS j
JOIN j16_community_users AS c ON c.userid = j.id
LEFT JOIN j16_session AS s ON s.userid = j.id
LEFT JOIN j16_session AS s ON s.userid = j.id
LEFT JOIN j16_x5_fastchat_users AS a ON a.userid = j.id
WHERE j.id IN (62,66,2692)

关于mysql - 使用 IF 语句进行查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8743578/

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