gpt4 book ai didi

MySQL:如果在什么地方?

转载 作者:行者123 更新时间:2023-11-29 05:38:07 25 4
gpt4 key购买 nike

我的查询从 MySQL 数据库中选择任务。每个任务都有一个组 ID,如果该组等于 0,那么如果该任务来自运行此查询的用户,那么它就是我只想返回的私有(private)任务。希望这是有道理的:-)

SELECT t.id, t.title, t.created_by, u.username
FROM (p_tasks AS t)
LEFT JOIN p_groups AS g ON t.group_id = g.id
JOIN p_users AS u ON t.assigned_to_user_id = u.id
WHERE
(
t.assigned_to_user_id = $user_id OR
t.owner_user_id = $user_id
)
AND
(
g.priority >= '10' OR
t.group_id = 0
)
AND
(
t.status != "approved" AND
t.status != "closed"
)
ORDER BY c.name

如何只为创建任务的人返回 group_id = 0 的任务?

最佳答案

不确定我是否完全理解您的查询,但您描述的部分看起来像这样。这假定您希望将所有公共(public)任务和所有私有(private)任务分配给用户或由用户拥有。

WHERE  
(
(t.assigned_to_user_id = $user_id OR t.owner_user_id = $user_id) AND
t.group_id = 0
)
OR
(
t.group_id != 0
)

关于MySQL:如果在什么地方?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9023099/

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