MySQL:如果在哪里?
我的查询从 MySQL 数据库中选择任务。每个任务都有一个组 ID,如果该组等于 0,则它是一个私有任务,如果该任务来自运行此查询的用户,我只想返回。希望这是有道理的:-)
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 的任务?
My query selects tasks from a MySQL DB. Each task has a group id and if the group is equal 0 it is a private task I want only return, if the task is from the user who runs this query. Hope that makes sense :-)
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
How can I return the tasks with group_id = 0 only for those who had created the tasks?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
不确定我完全理解您的查询,但您描述的部分看起来像这样。这假设您希望将所有公共任务和所有私人任务分配给用户或由用户拥有。
Not sure I understand your query completely, but the part you have described would look something like this. This assumes you want all public tasks and all private ones assigned to the user or owned by the user.
您应该能够在不使用 IF 语句的情况下构造 where 子句。
You should be able to construct your where clause without using an IF statement.
我不完全理解你的意思,但就像英语一样,清晰的语法是:
I do not full understud what you mean, but like in english, the clear syntax is:
感谢大家!我想我知道了。
当我删除
t.group_id = 0
时,它似乎就是我想要的:-)如果我是所有者,我会通过
owner_user_id
或signed_to_user_id
选择任务。如果我不是,那么该任务是否是私有的(group_id = 0
)并不重要,因为我没有足够的权限来选择/查看它。明天我会尝试一下。
再次感谢您的帮助!!
Thanks to all! I think I get it know.
When I delete
t.group_id = 0
it seems to be what I want :-)If I am the owner I select the task by
owner_user_id
orassigned_to_user_id
. If I am not, it doesn't matter if the task is private (group_id = 0
), because I don't have enough privileges to select/view it.I'll try that tomorrow.
Thanks again for your help!!