2014-02-21 59 views
0

我想從表sabha_cluster中選擇不同的記錄。我使用了下面的查詢,但是「Mysql每個派生表都必須有它自己的別名錯誤」。Mysql每個派生表必須有它自己的別名錯誤

mysql> select mps.scode,mps.tlit,mps.amnt,mps.pr from milk_payment_summary mps 
join society_master s on mps.scode=s.scode inner join (select distinct c.scode 
rom sabha_cluster c) where mps.date1 between '2014-01-16' and '2014-02-15' && c.scode=44; 

回答

0

一個別名添加到派生表,如下所示:

select mps.scode,mps.tlit, mps.amnt,mps.pr 
from milk_payment_summary mps 
join society_master s 
on mps.scode=s.scode 
join (
    select distinct c.scode from sabha_cluster c 
) AS t 
on t.scode = s.scode 
where mps.date1 between '2014-01-16' and '2014-02-15' and t.scode=44 

這裏t是派生表的別名。

+0

選擇mps.scode,mps.tlit,mps.amnt,mps.pr 從milk_payment_summary MPS 加入society_master s^ 上mps.scode = s.scode 加入( 選擇從sabha_clusterç 不同c.scode)AS上t.scode = s.scode 其中 '2014年1月16日' 之間mps.date1和「2014噸 -02-15'和t.scode = 44 –

0

試試這個

select 
    mps.scode, mps.tlit, mps.amnt, mps.pr 
from 
    milk_payment_summary mps 
     join 
    society_master s ON mps.scode = s.scode 
     inner join 
    (select distinct 
     c.scode 
    from 
     sabha_cluster c) d 
where 
    mps.date1 between '2014-01-16' and '2014-02-15' 
     AND d.scode = 44; 
2

你需要一個別名爲您的子查詢:

mysql> select mps.scode,mps.tlit,mps.amnt,mps.pr from milk_payment_summary mps 
join society_master s on mps.scode=s.scode inner join (select distinct c.scode 
from sabha_cluster c) x where mps.date1 between '2014-01-16' and '2014-02-15' && x.scode=44; 

請注意,您必須使用相同的別名,而不是c,在WHERE子句。

0

你可以通過這個代碼..........

select mps.scode,mps.tlit,mps.amnt,mps.pr from milk_payment_summary mps 
    join society_master s on mps.scode=s.scode inner join (select distinct scode 
    from sabha_cluster) as c where mps.scode=c.scode and (mps.date1 between '2014-01-16' and '2014-02-15') and c.scode=44; 
相關問題