开发者

SQL statement error

mysql> Select Emp_B AS Total
    -> From (Select Sum(mines.NoOfWorkers) AS Emp_B from mines);
ERROR 1248 (42000): Every derived table must have its own alias

mysql> Select Emp_B AS Total
    -> From (Select Sum(mines.NoOfWorkers) from mines) AS Emp_B;
ERROR 1054 (42S22): Unknown column 'Emp_B' in 'field list'

I am having some prob开发者_开发问答lem with this SQL statement. Any assistance will be mose appreciated


Select Emp_B AS Total
From (Select Sum(mines.NoOfWorkers) AS Emp_B from mines) x;

As the error states Every derived table must have its own alias Just give it an alias, like x above. OR AS x, but the AS word is optional.

Or why alias it twice...

Select Total
From (Select Sum(mines.NoOfWorkers) AS Total from mines) x;

But since SUM gives you exactly one value, unless you have simplified the query from some larger one, this gives exactly the same result??

Select Sum(mines.NoOfWorkers) AS Total from mines;


This should work for you; however, if you're only doing this one sub select into a temp table it's kind of a waste to wrap it into another select but that's just IMHO.

Select Emp_B.sum From (Select Sum(mines.NoOfWorkers) as sum from mines) AS Emp_B;


Select temp.total  
From 
  ( Select Sum(mines.NoOfWorkers) AS total 
    from mines
  ) AS temp
;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜