简体   繁体   English

MySQL查询不从哪里条件中获取数据

[英]mysql query not fetching data from where condition

I have written a MySQL query ?I want to fetch data t.taskid = b.id OR t.taskid = '0' AND t.subtaskid = j.id OR t.subtaskid = '0' from this but where condition is not working for this 我写了一个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' 

If t.taskid = b.id t.subtaskid = j.id are to be joins then check whether you can modify 如果要加入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'

the above lines with proper joins. 以上行有适当的联接。 Because using join conditions in where clause can create cross join instead of intended one. 因为在where子句中使用联接条件可以创建交叉联接,而不是预期的交叉联接。

If it do not work 如果不起作用

Try with using having clause instead of where clause and don't forget to use group by 尝试使用having clause代替where clause ,不要忘记使用group by

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM