select voucherid,name,min(discount) from (
select * from (select c.taid,d.said,a.voucherid,a.name,b.discount,e.avgprice,d.sname,c.tname,e.reviews,a.voucherfrom,a.voucherlogo,a.couflag,a.disflag 
from ((select * from zt_sh_voucher where disable=0 and  status=0 and sstatus=1 and pid=1001 and cityid=351 and taid=248 and keyword like '%%') a 
inner join zt_sh_thrarea c on a.taid=c.taid and c.taid=248 inner join zt_sh_secsarea d on c.said=d.said and d.said=20
inner join zt_sh_vouchershops e on a.voucherid = e.voucherid)
left join (select * from zt_sh_carddiscounts where status=1 and disable=0  and date_format(starttime,'%Y-%m-%d')<='2010-12-15' 
and date_format(endtime,'%Y-%m-%d')>='2010-12-15') b  on a.voucherid = b.voucherid)) v group by v.voucherid,v.name;
在mysql中执行报错 错误信息如下:Error Code : 1248
Every derived table must have its own alias

解决方案 »

  1.   

    select voucherid,name,min(discount) from (
    select * from (
    select c.taid,d.said,a.voucherid,a.name,b.discount,
    e.avgprice,d.sname,c.tname,e.reviews,a.voucherfrom,a.voucherlogo,a.couflag,a.disflag 
    from (
    (select * from zt_sh_voucher 
    where disable=0 and status=0 and sstatus=1 and pid=1001 and cityid=351 and taid=248 and keyword like '%%') a 
    inner join zt_sh_thrarea c on a.taid=c.taid and c.taid=248 inner join zt_sh_secsarea d on c.said=d.said and d.said=20
    inner join zt_sh_vouchershops e on a.voucherid = e.voucherid) tttt
    left join (select * from zt_sh_carddiscounts where status=1 and disable=0 and date_format(starttime,'%Y-%m-%d')<='2010-12-15' 
    and date_format(endtime,'%Y-%m-%d')>='2010-12-15') b on a.voucherid = b.voucherid))
     v group by v.voucherid,v.name;
      

  2.   


    我把这个在mysql中执行还是报这个错啊 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'tttt
    left join (select * from zt_sh_carddiscounts where status=1 and disable=0 a' at line 9
      

  3.   

    select voucherid,name,min(discount) from (
    select * from (select c.taid,d.said,a.voucherid,a.name,b.discount,e.avgprice,d.sname,c.tname,e.reviews,a.voucherfrom,a.voucherlogo,a.couflag,a.disflag  
    from ((select * from zt_sh_voucher where disable=0 and  status=0 and sstatus=1 and pid=1001 and cityid=351 and taid=248 and keyword like '%%') a  
    inner join zt_sh_thrarea c on a.taid=c.taid and c.taid=248 inner join zt_sh_secsarea d on c.said=d.said and d.said=20
    inner join zt_sh_vouchershops e on a.voucherid = e.voucherid) v2
    left join (select * from zt_sh_carddiscounts where status=1 and disable=0  and date_format(starttime,'%Y-%m-%d')<='2010-12-15'  
    and date_format(endtime,'%Y-%m-%d')>='2010-12-15') b  on a.voucherid = b.voucherid)v1 ) v group by v.voucherid,v.name;
      

  4.   

    wangli88911520 (wangli88911520)
      '截至2010-12-20 12:38:34  用户结帖率0.00%当您的问题得到解答后请及时结贴.
    http://topic.csdn.net/u/20090501/15/7548d251-aec2-4975-a9bf-ca09a5551ba5.html
    http://topic.csdn.net/u/20100428/09/BC9E0908-F250-42A6-8765-B50A82FE186A.html
    http://topic.csdn.net/u/20100626/09/f35a4763-4b59-49c3-8061-d48fdbc29561.html8、如何给分和结贴?
    http://community.csdn.net/Help/HelpCenter.htm#结帖
      

  5.   

    报错 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'v2
    left join (select * from zt_sh_carddiscounts where status=1 and disable=0 and' at line 5
      

  6.   

    select voucherid,name,min(discount) from (
    select * from (select c.taid,d.said,a.voucherid,a.name,b.discount,e.avgprice,d.sname,c.tname,e.reviews,a.voucherfrom,a.voucherlogo,a.couflag,a.disflag 
    from ((select * from zt_sh_voucher where disable=0 and  status=0 and sstatus=1 and pid=1001 and cityid=351 and taid=248 and keyword like '%%') a 
    inner join zt_sh_thrarea c on a.taid=c.taid and c.taid=248 inner join zt_sh_secsarea d on c.said=d.said and d.said=20
    inner join zt_sh_vouchershops e on a.voucherid = e.voucherid) 
    left join (select * from zt_sh_carddiscounts where status=1 and disable=0  and date_format(starttime,'%Y-%m-%d')<='2010-12-15' 
    and date_format(endtime,'%Y-%m-%d')>='2010-12-15') b  on a.voucherid = b.voucherid)v1 ) v group by v.voucherid,v.name;