这个sql如何关联2张表
程序员文章站
2024-01-10 18:33:25
...
原sql语句为:
SELECT * from ( SELECT DISTINCT *, year( from_unixtime(time ) ) year, month( from_unixtime(time ) ) month FROM A表 WHERE id = 1) as a WHERE is_del =0 AND year = 1 AND month = 1 order by time DESC
现在我想关联B表.如何查询?
A表.id=B表.id
SELECT * from ( SELECT DISTINCT *, year( from_unixtime(time ) ) year, month( from_unixtime(time ) ) month FROM A表 WHERE id = 1) as a WHERE is_del =0 AND year = 1 AND month = 1 order by time DESC
现在我想关联B表.如何查询?
A表.id=B表.id
回复讨论(解决方案)
SELECT * from ( SELECT DISTINCT *, year( from_unixtime(time ) ) year, month( from_unixtime(time ) ) month FROM A表 WHERE id = 1) as a , B表 b WHERE a.id=b.ai and is_del =0 AND year = 1 AND month = 1 order by time DESC
下一篇: php统计中文数量的简单实现方法