【问题标题】:MYSQL Error code 1248 Every derived table must have it's own aliasMYSQL 错误代码 1248 每个派生表都必须有自己的别名
【发布时间】:2017-11-05 17:52:21
【问题描述】:

MYSQL 错误代码 1248 每个派生表都必须有自己的别名

select supplier_id, supplier_name, strong_answers from 
(select campaign_suppliers.id supplier_id, campaign_suppliers.supplier_name supplier_name, 
count(case when supplier_answers.binary_answer is not null 
or supplier_answers.value_answer is not null then 1 end) strong_answers 
from supplier_answers join campaign_suppliers on (supplier_answers.supplier_id = campaign_suppliers.id) 
where supplier_answers.campaign_id = 1 group by campaign_suppliers.id, campaign_suppliers.supplier_name 
having count(case when supplier_answers.binary_answer is not null 
or supplier_answers.value_answer is not null then 1 end) >=  
(select count(distinct supplier_answers.question_index) from supplier_answers where campaign_id = 1)) 
where strong_answers >= (select count(distinct supplier_answers.question_index) from supplier_answers where campaign_id = 1)

【问题讨论】:

    标签: mysql alias


    【解决方案1】:

    from ( ... ) t 需要一个表名别名,请参见下面的// <---- 符号

    select t.supplier_id, t.supplier_name, t.strong_answers from (
        select campaign_suppliers.id supplier_id, campaign_suppliers.supplier_name supplier_name, 
        count(case when supplier_answers.binary_answer is not null 
          or supplier_answers.value_answer is not null then 1 end) strong_answers 
    from supplier_answers join campaign_suppliers on (supplier_answers.supplier_id = campaign_suppliers.id) 
    where supplier_answers.campaign_id = 1 group by campaign_suppliers.id, campaign_suppliers.supplier_name 
    having count(case when supplier_answers.binary_answer is not null 
    or supplier_answers.value_answer is not null then 1 end) >=  
    (select count(distinct supplier_answers.question_index) 
            from supplier_answers where campaign_id = 1)) t //<----  here you need  a table name eg: t
    where t.strong_answers >= (select count(distinct supplier_answers.question_index) from supplier_answers where campaign_id = 1)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-16
      • 2014-04-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多