我已经编写了一个MySQL查询?我想从中获取数据t.taskid = b.id OR t.taskid = '0' AND t.subtaskid = j.id OR t.subtaskid = '0'
,但条件对此不起作用
SELECT t.id as id
, t.taskid
, t.subtaskid
, p.PNAME AS projectname
, t.date AS DATE
, b.Summary AS tasks
, j.SUMMARY AS subtasks
, t.mon AS time1
, t.tue AS time2
, t.wed AS time3
, t.thu AS time4
, t.fri AS time5
, t.sat AS time6
, t.sun AS time7
FROM bt_createissue b
, bt_createissue j
, timesheet t
LEFT
JOIN bt_project p
ON t.projectid = p.pkey
WHERE t.taskid = b.id
OR t.taskid = 0
AND t.subtaskid = j.id
OR t.subtaskid = 0
AND t.date >= '2015-03-09'
AND t.date <= '2015-03-30'
AND t.username = '$username'
最佳答案
如果要加入t.taskid = b.idt.subtaskid = j.id
,请检查是否可以修改WHERE t.taskid = b.id OR t.taskid = '0'AND t.subtaskid = j.id OR t.subtaskid = '0'
以上行有适当的联接。
因为在where子句中使用联接条件可以创建交叉联接而不是预期的交叉联接。
如果不起作用
尝试使用having clause
代替where clause
,并且不要忘记使用group by