MYSQL 错误 1248 (42000):每个派生表必须有自己的别名
我一生都无法弄清楚为什么这是错误的
SELECT * FROM
SELECT
c.city_id,
p.prop_ynow_id,
p.propertyid,
p.prop_add_value,
p.name,
picture,
ifnull(p.address,'') as`location`,
ifnull(city,'')as`city`,
ifnull(ShortCut,'') as `state`,
ifnull(p.zip,'') as `zip`,
min(if(pr.minrent = 0,99999999,pr.minrent)) as minrent,
max(pr.maxrent) as maxrent,
'' as service,
hood_id,
ifnull(p.phone,'') as `phone`,
latitude,
longitude,
min(CAST(pu.fullBath AS UNSIGNED)) as`minbath`,
max(CAST(pu.fullBath AS UNSIGNED)) as`maxbath`,
min(CAST(pu.Bed AS UNSIGNED)) as`minbed` ,
max(CAST(pu.Bed AS UNSIGNED)) as`maxbed`,
'' as url,
'' as source_id,
'' as source_name,
'' as addresscode,
'' as citycode,
'' as ctime,
'' as paid,
'' as similar_url,
'' as created_at,
'' as updated_at,
'' as city_name,
'' as service_listing_id
FROM
wiki_city_list c join propertyinfo p on c.city_id=p.city
join ynow_rentwiki.Property_Unitlayout pu on p.prop_ynow_id=pu.P_Ident
join (SELECT CAST(substring_index(if(Rent >0 ,Rent,RentLow),'.',1) AS UNSIGNED) as minrent, CAST(substring_index(if(Rent >0,Rent,Renthigh),'.',1) AS UNSIGNED) as maxrent,PRE_Ident,P_Ident,UNL_Ident,RTY_Ident from ynow_rentwiki.Property_rents where P_Ident in (3958, 4576, 4577) and (Rent!='' or (Rentlow!='' and Renthigh!='')) ) as pr on pu.UNL_Ident=pr.UNL_Ident
join state s on (p.state = s.stateid OR p.state = s.ShortCut )
WHERE
pu.Status='Active'
and p.delete_date='0000-00-00'
GROUP BY
c.city_id, p.prop_ynow_id
UNION
SELECT
c.city_id,
p.prop_ynow_id,
p.propertyid,
p.prop_add_value,
p.name,
picture,
ifnull(p.address,'') as`location`,
ifnull(city,'')as`city`,
ifnull(ShortCut,'') as `state`,
ifnull(p.zip,'') as `zip`,
min(if(pr.minrent = 0,99999999,pr.minrent)) as minrent,
max(pr.maxrent) as maxrent,
'' as service,
hood_id,
ifnull(p.phone,'') as `phone`,
latitude,
longitude,
min(CAST(pu.fullBath AS UNSIGNED)) as`minbath`,
max(CAST(pu.fullBath AS UNSIGNED)) as`maxbath`,
min(CAST(pu.Bed AS UNSIGNED)) as`minbed` ,
max(CAST(pu.Bed AS UNSIGNED)) as`maxbed`,
'' as url,
'' as source_id,
'' as source_name,
'' as addresscode,
'' as citycode,
'' as ctime,
'' as paid,
'' as similar_url,
'' as created_at,
'' as updated_at,
'' as city_name,
'' as service_listing_id
FROM
wiki_city_list c join propertyinfo p on c.city_id=p.city
join ynow_rentwiki.Property_Unitlayout pu on p.prop_ynow_id=pu.P_Ident
join (SELECT CAST(substring_index(if(Rent >0 ,Rent,RentLow),'.',1) AS UNSIGNED) as minrent, CAST(substring_index(if(Rent >0,Rent,Renthigh),'.',1) AS UNSIGNED) as maxrent,PRE_Ident,P_Ident,UNL_Ident,RTY_Ident from ynow_rentwiki.Property_rents where P_Ident in (9744) and (Rent!='' or (Rentlow!='' and Renthigh!='')) ) as pr on pu.UNL_Ident=pr.UNL_Ident
join state s on (p.state = s.stateid OR p.state = s.ShortCut )
WHERE
pu.Status='Active'
and p.delete_date='0000-00-00'
GROUP BY
c.city_id, p.prop_ynow_id
UNION
SELECT
'' as prop_ynow_id,
id as propertyid,
0 as prop_add_value,
t.name as name,
'' as picture,
t.address as location,
t.city as city,
s.ShortCut as state,
t.zip as zip,
CAST(REPLACE(REPLACE(t.price,'$',''),',','') as UNSIGNED) as minrent,
'' as maxrent,
t.service as service,
'' as hood_id,
'' as phone,
t.latitude as latitude,
t.longitude as longitude,
t.bathrooms as minbath,
'' as maxbath,
t.bedrooms as minbed,
'' as maxbed,
t.url as url,
t.source_id as source_id,
t.source_name as source_name,
t.addresscode as addresscode,
t.citycode as citycode,
t.ctime as ctime,
t.paid as paid,
t.similar_url as similar_url,
t.created_at as created_at,
t.updated_at as updated_at,
SUBSTRING_INDEX(c.city_name,'_',1) as city_name,
t.service_listing_id as service_listing_id
FROM LBCPrimary.third_party_properties as t, LBCPrimary.wiki_city_list as c, LBCPrimary.state as s
WHERE
t.city in ( '230' )
and
address <> '' and
t.city = c.city_id and
c.city_state = s.stateid
order by t.ctime
desc
limit 46 as a limit 0,50
I cant for the life of me figure out why this is erroring
SELECT * FROM
SELECT
c.city_id,
p.prop_ynow_id,
p.propertyid,
p.prop_add_value,
p.name,
picture,
ifnull(p.address,'') as`location`,
ifnull(city,'')as`city`,
ifnull(ShortCut,'') as `state`,
ifnull(p.zip,'') as `zip`,
min(if(pr.minrent = 0,99999999,pr.minrent)) as minrent,
max(pr.maxrent) as maxrent,
'' as service,
hood_id,
ifnull(p.phone,'') as `phone`,
latitude,
longitude,
min(CAST(pu.fullBath AS UNSIGNED)) as`minbath`,
max(CAST(pu.fullBath AS UNSIGNED)) as`maxbath`,
min(CAST(pu.Bed AS UNSIGNED)) as`minbed` ,
max(CAST(pu.Bed AS UNSIGNED)) as`maxbed`,
'' as url,
'' as source_id,
'' as source_name,
'' as addresscode,
'' as citycode,
'' as ctime,
'' as paid,
'' as similar_url,
'' as created_at,
'' as updated_at,
'' as city_name,
'' as service_listing_id
FROM
wiki_city_list c join propertyinfo p on c.city_id=p.city
join ynow_rentwiki.Property_Unitlayout pu on p.prop_ynow_id=pu.P_Ident
join (SELECT CAST(substring_index(if(Rent >0 ,Rent,RentLow),'.',1) AS UNSIGNED) as minrent, CAST(substring_index(if(Rent >0,Rent,Renthigh),'.',1) AS UNSIGNED) as maxrent,PRE_Ident,P_Ident,UNL_Ident,RTY_Ident from ynow_rentwiki.Property_rents where P_Ident in (3958, 4576, 4577) and (Rent!='' or (Rentlow!='' and Renthigh!='')) ) as pr on pu.UNL_Ident=pr.UNL_Ident
join state s on (p.state = s.stateid OR p.state = s.ShortCut )
WHERE
pu.Status='Active'
and p.delete_date='0000-00-00'
GROUP BY
c.city_id, p.prop_ynow_id
UNION
SELECT
c.city_id,
p.prop_ynow_id,
p.propertyid,
p.prop_add_value,
p.name,
picture,
ifnull(p.address,'') as`location`,
ifnull(city,'')as`city`,
ifnull(ShortCut,'') as `state`,
ifnull(p.zip,'') as `zip`,
min(if(pr.minrent = 0,99999999,pr.minrent)) as minrent,
max(pr.maxrent) as maxrent,
'' as service,
hood_id,
ifnull(p.phone,'') as `phone`,
latitude,
longitude,
min(CAST(pu.fullBath AS UNSIGNED)) as`minbath`,
max(CAST(pu.fullBath AS UNSIGNED)) as`maxbath`,
min(CAST(pu.Bed AS UNSIGNED)) as`minbed` ,
max(CAST(pu.Bed AS UNSIGNED)) as`maxbed`,
'' as url,
'' as source_id,
'' as source_name,
'' as addresscode,
'' as citycode,
'' as ctime,
'' as paid,
'' as similar_url,
'' as created_at,
'' as updated_at,
'' as city_name,
'' as service_listing_id
FROM
wiki_city_list c join propertyinfo p on c.city_id=p.city
join ynow_rentwiki.Property_Unitlayout pu on p.prop_ynow_id=pu.P_Ident
join (SELECT CAST(substring_index(if(Rent >0 ,Rent,RentLow),'.',1) AS UNSIGNED) as minrent, CAST(substring_index(if(Rent >0,Rent,Renthigh),'.',1) AS UNSIGNED) as maxrent,PRE_Ident,P_Ident,UNL_Ident,RTY_Ident from ynow_rentwiki.Property_rents where P_Ident in (9744) and (Rent!='' or (Rentlow!='' and Renthigh!='')) ) as pr on pu.UNL_Ident=pr.UNL_Ident
join state s on (p.state = s.stateid OR p.state = s.ShortCut )
WHERE
pu.Status='Active'
and p.delete_date='0000-00-00'
GROUP BY
c.city_id, p.prop_ynow_id
UNION
SELECT
'' as prop_ynow_id,
id as propertyid,
0 as prop_add_value,
t.name as name,
'' as picture,
t.address as location,
t.city as city,
s.ShortCut as state,
t.zip as zip,
CAST(REPLACE(REPLACE(t.price,'
,''),',','') as UNSIGNED) as minrent,
'' as maxrent,
t.service as service,
'' as hood_id,
'' as phone,
t.latitude as latitude,
t.longitude as longitude,
t.bathrooms as minbath,
'' as maxbath,
t.bedrooms as minbed,
'' as maxbed,
t.url as url,
t.source_id as source_id,
t.source_name as source_name,
t.addresscode as addresscode,
t.citycode as citycode,
t.ctime as ctime,
t.paid as paid,
t.similar_url as similar_url,
t.created_at as created_at,
t.updated_at as updated_at,
SUBSTRING_INDEX(c.city_name,'_',1) as city_name,
t.service_listing_id as service_listing_id
FROM LBCPrimary.third_party_properties as t, LBCPrimary.wiki_city_list as c, LBCPrimary.state as s
WHERE
t.city in ( '230' )
and
address <> '' and
t.city = c.city_id and
c.city_state = s.stateid
order by t.ctime
desc
limit 46 as a limit 0,50
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
正如它所说的那样 - 每个派生表必须有一个别名。
SELECT a.* FROM (SELECT ....)a
更新。
这应该适合你:
It means exactly what it says - each derived table must have an alias.
SELECT a.* FROM (SELECT ....)a
Update.
This should work for you:
查询的第一行
似乎是不必要的(因为所有三个 UNIONed 查询已经包含 SELECT 和 FROM 子句)。
删除这条不必要的线应该可以解决问题;或者,在第一行之后添加
(
,并在末尾添加) QRYALIAS
也可以解决该问题。The very first line of your query is
which appears to be unnecessary (as all three UNIONed queries already include SELECT and FROM clauses).
Removing this unnecessary line should resolve the problem; alternatively, adding a
(
just after the first line, and adding a) QRYALIAS
at the end would also resolve the problem.选择 h.黑客_id,
h.姓名,
COUNT (c.challenge_id) AS 总数
来自黑客h,
挑战c
其中 h.hacker_id,
h.姓名
HAVING COUNT (c.challenge_id) IN (SELECT MAX (total))
FROM (SELECT COUNT () AS Total FROM Challenge GROUP BY hacker_id))
或 COUNT (c.challenge_id) IN
(选择总计
从
(SELECT COUNT () AS 总计
来自挑战
按 hacker_id 分组)
按总计分组
有计数(总计)=1)
按计数排序 (c.challenge_id) DESC, h.黑客_id;
SELECT h. hacker_id,
h. name,
COUNT (c. challenge_id) AS total
FROM hackers h,
challenges c
WHERE h.hacker_id,
h. name
HAVING COUNT (c. challenge_id) IN (SELECT MAX (total)
FROM (SELECT COUNT () AS total FROM challenge GROUP BY hacker_id))
OR COUNT (c. challenge_id) IN
(SELECT total
FROM
(SELECT COUNT () AS total
FROM challenges
GROUP BY hacker_id)
GROUP BY total
HAVING COUNT (total)=1)
ORDER BY COUNT (c. challenge_id) DESC, h. hacker_id;