一般的报表查询要用到 join left 或子查询 但是我习惯用join的方式
select a.colum1 ,b.colum2,c.colum3 from tb1 a
join left
(select colum2 from tb2 where 1 = 1) b
on
a.colum_id = b.colum_id
join left
(select colum_id count(colum3) colum3 from tb3 where 1 =1 group by colum3 ) b
on
b.colum_id = a.colum_id where 1=1
如果还没有一目了然在查一下join left 的作用,其他语句一次类推,很容易解决比较变态的报表
select a.colum1 ,b.colum2,c.colum3 from tb1 a
join left
(select colum2 from tb2 where 1 = 1) b
on
a.colum_id = b.colum_id
join left
(select colum_id count(colum3) colum3 from tb3 where 1 =1 group by colum3 ) b
on
b.colum_id = a.colum_id where 1=1
如果还没有一目了然在查一下join left 的作用,其他语句一次类推,很容易解决比较变态的报表