select
ag.name, aa.name, al.object_id, u.name, al.performed_by, al.datetime,
aa1.name, et.name, ald.name, ald.value
from
'db'.'table1' al, 'db'.'table2' ald, 'db'.'table3' ag,
'db'.'table4' aa, 'db'.'table5' aa1, 'db'.'table6' et,
'db'.'table7' u
where
al.id = ald.log_id
and al.datetime > DATE_SUB(sysdate(). INTERVAL 90 DAY)
and al.group_id = ag.id
and ag.name = 'User'
and al.action_id = aa1.id
and al.object_id = u.user_id
and ald.type_id = et.id;
上面的查询在mysql中返回空集,但数据存在。如何排除故障?
请帮忙...... 在此先感谢....
答案 0 :(得分:0)
不要在表数据库周围使用单引号,而是使用列名作为反引号。
试试这个:
from
`db`.`table1` al, `db`.`table2` ald, `db`.`table3` ag,
`db`.`table4` aa, `db`.`table5` aa1, `db`.`table6` et,
`db`.`table7` u
尝试使用连接
select
ag.name, aa.name, al.object_id, u.name, al.performed_by, al.datetime,
aa1.name, et.name, ald.name, ald.value
from
`db`.`table1` al
Inner join `db`.`table2` ald On al.id = ald.log_id
Inner join `db`.`table3` ag On al.group_id = ag.id
Inner join `db`.`table4` aa On """""the condition of relation with this table""""
Inner join `db`.`table5` aa1 On al.action_id = aa1.id
Inner join `db`.`table6` et On ald.type_id = et.id
Inner join `db`.`table7` u On al.object_id = u.user_id
where
al.datetime > DATE_SUB(sysdate(), INTERVAL 90 DAY)
and ag.name = 'User'