0

我正在尝试运行此查询:

SELECT DISTINCT col1 
FROM 
  (
   SELECT CONCAT(retailerId,'_recharge') FROM retailerinformation
   WHERE Channel='videocon' AND retailerId='kioskpb20130909045617'
  )

但每次运行时我都会收到此错误:

Error Code : 1248 Every derived table must have its own alias
4

4 回答 4

3

你的错误很清楚。创建别名:

SELECT DISTINCT 
  col1 
FROM 
  (select concat(retailerId,'_recharge') from retailerinformation where Channel='videocon' and retailerId='kioskpb20130909045617') AS tmp_table

提示:如果您尝试理解错误,而不仅仅是阅读它们 - 这将是成功的故事。

于 2013-10-10T11:21:34.873 回答
0

这将起作用:

SELECT 
DISTINCT col1
FROM (
   SELECT concat(retailerId,'_recharge') 
   FROM retailerinformation where Channel='videocon' and retailerId='kioskpb20130909045617'
   ) AS alias
于 2013-10-10T11:25:21.030 回答
0

除了在子查询中添加别名之外,在外部查询中调用的列应该存在于子查询中。在这种情况下,col1 应该存在于子查询中。话虽如此,这应该有效

SELECT DISTINCT col1 
FROM 
  (
   SELECT CONCAT(retailerId,'_recharge') col1 FROM retailerinformation
   WHERE Channel='videocon' AND retailerId='kioskpb20130909045617'
  ) sub
于 2013-10-10T12:15:22.160 回答
0

试试这个版本:

select DISTINCT col1 from 
 (select concat(retailerId,'_recharge') from retailerinformation
   where Channel='videocon' and retailerId='kioskpb20130909045617') as retailerino

请注意子查询中的别名。

于 2013-10-10T11:22:28.767 回答