在我的查询中,如果用户选择“Jack”,我有一个特定的条件,我应该在我的查询中跳过一个连接,通常如果以下计数结果是0,我应该跳过连接:
这是我的条件:
select count (f.m_supervisor) from wpv.v_master f
JOIN zd.t_users g on(g.user_id=f.pv_personid)
where g.user_name Like('Jack')
上面连接的结果是0,所以我应该跳过以下查询中的连接
select sum(energy::numeric) Production,name, round(avg(mspeed), 2) speed, round(avg(m_cor), 2) avai
from wpv.v_daily v1
left outer join wh.t_ext t1 on t1.m_id = v1.m_id and t1.m_date=v1.m_date
JOIN wpv.v_master f on (f.m_tid=v1.m_tid)
JOIN zd.t_users g on(g.user_id=f.pv_personid)
where (v1.m_date between '19/04/2018' and '20/04/2018') AND g.user_name Like('%')
and f.service Like('%')
and f.m_supervisor like ('%')----->This line should be skipped if count is 0
group by 2
order by 4 ASC