我写了一个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'
答案 0 :(得分:0)
如果要加入t.taskid = b.id
t.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