语法错误辅助

时间:2016-07-19 02:46:30

标签: mysql sql

我的语法有什么问题?

select sum(a.total) from (
sum(`PCPrice` * TaxVariable) AS PCPriceTotal,
(select count(*)  from DBname where PCPriceTotal > 0 ) as total
from DBname group by PCPriceTotal) as a
  

您的SQL语法有错误;查看与您的MySQL服务器版本对应的手册,以便在'sum(PCPrice * TaxVariable)AS PCPriceTotal附近使用正确的语法,(从第2行的DBname'中选择count(*)

解决。简单的错误。错过了“选择”。修正:

select sum(a.total) from (
select sum(`PCPrice` * TaxVariable) AS PCPriceTotal,
(select count(*)  from DBname where PCPriceTotal > 0 ) as total
from DBname group by PCPriceTotal) as a

2 个答案:

答案 0 :(得分:1)

您忘记在您的子查询中加上'SELECT',它位于SUM(`PCPrice` * TaxVariable) AS PCPriceTotal之前。

SELECT SUM(a.total) FROM 
(SELECT
    SUM(`PCPrice` * TaxVariable) AS PCPriceTotal,
    (SELECT COUNT(*)  FROM DBname WHERE PCPriceTotal > 0 ) AS total
    FROM DBname GROUP BY PCPriceTotal
) AS a

答案 1 :(得分:0)

您正在使用函数代替表(sum(PCPrice * TaxVariable)AS PCPriceTotal

你的要求是什么。