mysql语句错误,求解

wangli88911520 2010-12-20 10:31:30
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
...全文
69 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
ACMAIN_CHM 2010-12-20
  • 打赏
  • 举报
回复
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;
zuoxingyu 2010-12-20
  • 打赏
  • 举报
回复
子表这么多啊,每个子表都给它起个别名就行了。
wangli88911520 2010-12-20
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 wxf163 的回复:]
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
……
[/Quote]

我把这个在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
a785126172 2010-12-20
  • 打赏
  • 举报
回复
楼上正解 你少了个别名 就会报这个错误
王向飞 2010-12-20
  • 打赏
  • 举报
回复
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;
wangli88911520 2010-12-20
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 acmain_chm 的回复:]
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
fro……
[/Quote]

对了。。。非常感谢!
ACMAIN_CHM 2010-12-20
  • 打赏
  • 举报
回复
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;
wangli88911520 2010-12-20
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 acmain_chm 的回复:]
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
fr……
[/Quote]
报错 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

56,678

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧