MySQL - 如何使用左和右连接来获得结果

时间:2016-02-26 04:44:31

标签: mysql

我知道aw_id,ad_id和grp_id的值(例如,aw_id = 5,ad_id = 46和grp_id = 2)。

我想显示所有的at_cub_details:

at_cub_details.grp_id = 2 AND
at_cub_details.cd_id = at_cub_awards.cd_id AND 
at_cub_awards.aw_id = 5 AND 
at_cub_awards.ca_awarded_date IS NULL 
OR at_cub_details.cd_id = at_cub_awards.cd_id AND 
at_cub_awards.aw_id = 5 does not exist

Where at_cub_details.cd_id = at_cub_awards.cd_id AND 
at_cub_awards.aw_id = 5 AND 
at_cub_awards.ca_awarded_date = NULL does exist **then** 
at_cub_awards.ca_id = at_cub_award_date.ca_id 
AND at_cub_award_date.ad_id = 46 
AND at_cub_award_date.cad_task_completion_date IS NULL OR 
at_cub_awards.ca_id = at_cub_award_date.ca_id AND 
at_cub_award_date.ad_id = 46 does not exist

我已经尝试过各种各样的RIGHT和LEFT加入,没有任何运气。

1 个答案:

答案 0 :(得分:0)

解决方案是:

UIBarButtonItem