加入以下查询?

时间:2012-05-15 06:49:59

标签: mysql sql

我正在执行这两个查询。

1

select widget_uid,param_value as campaign_name
from widget_config_value
where widget_uid in (select widget_uid
                     from widget_config_value
                     where param_name="active"
                           and param_value="1"
                           and widget_uid in (select widget_uid
                                              from partner_widget
                                              where partner_uid=4)
                    )
       and param_name="widgetCampaignName";

2

select widget_uid,param_value as campaign_type
from widget_config_value
where widget_uid in (select widget_uid
                     from widget_config_value
                     where param_name="active"
                           and param_value="1"
                           and widget_uid in (select widget_uid
                                              from partner_widget
                                              where partner_uid=4)
                    )
      and  param_name="widgetType";

我如何在widget_uid上加入这个?所以,我可以得到常见的widget_uid的结果??

或者有没有办法改进上面的查询?

2 个答案:

答案 0 :(得分:1)

您可以通过以下方式尝试 -

select widget_uid, campaign_name, campaign_type from
(select widget_uid,param_value as campaign_name from widget_config_value 
where widget_uid in 
(select widget_uid from widget_config_value 
where param_name="active" 
and param_value="1" 
and widget_uid in (select widget_uid from partner_widget where partner_uid=4)) 
and param_name="widgetCampaignName") tbl1,
(select widget_uid,param_value as campaign_type 
from widget_config_value 
where widget_uid in 
(select widget_uid 
from widget_config_value 
where param_name="active" 
and param_value="1" 
and widget_uid in (select widget_uid from partner_widget where partner_uid=4)) 
and param_name="widgetType") tbl2
where tbl1.widget_uid = tbl2.widget_uid;

答案 1 :(得分:0)

我认为查询不起作用,因为

是不可能的
param_name="active" and param_name="widgetCampaignName" 

在同一时间。也查询没有。 2

查看您的查询

select 
    widget_uid,param_value as campaign_name 
from widget_config_value
where 
    widget_uid in (
        select widget_uid 
        from 
            widget_config_value 
        where 
            param_name="active" and 
            param_value="1" and 
            widget_uid in (
                select widget_uid 
                from partner_widget 
                where partner_uid=4)
            ) and
     param_name="widgetCampaignName";

在这部分

select widget_uid 
        from 
            widget_config_value 
        where 
            param_name="active" and 
            param_value="1" and 
            widget_uid in (
                select widget_uid 
                from partner_widget 
                where partner_uid=4)
            )

为您提供widget_config_value无法获得param_name not equal to "active"的数据。所以param_name="widgetCampaignName"没用。