SELECT account_name ,SUM(debit)+SUM(credit) AS 'total_balance'
AND SUM(total_balance) AS 'net_revenue'
FROM transaction
I want to find the total balance and the sum
of the total balance as net revenue and its giving me the following sql error
我想找到总余额和总余额之和作为净收入,它给我以下sql错误
#1064 - 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 'and sum(total_balance) as 'net_revenue' from transaction' at line 2
3 个解决方案
#1
0
Just remove the AND
.
只需删除AND。
SELECT
account_name,
SUM(debit)+SUM(credit) AS 'total_balance',
SUM(total_balance) AS 'net_revenue'
FROM transaction
Note: Although the above query is syntactically valid, SUM
is a group function and you'll probably need some GROUP BY
clause to select the account_name
correctly. Something like this:
注意:虽然上面的查询在语法上是有效的,但SUM是一个组函数,您可能需要一些GROUP BY子句才能正确选择account_name。像这样的东西:
SELECT
account_name,
SUM(debit)+SUM(credit) AS 'total_balance',
SUM(total_balance) AS 'net_revenue'
FROM transaction
GROUP BY account_name
#2
0
No, it is not valid SQL. Use commas to separate columns in the select-list.
不,它不是有效的SQL。使用逗号分隔选择列表中的列。
SELECT account_name ,SUM(debit)+SUM(credit) AS 'total_balance',
SUM(total_balance) AS 'net_revenue'
FROM transaction
The formation of list like apples, bananas and plums
is common in natural English language, but not in code.
苹果,香蕉和李子等列表的形成在自然英语中很常见,但在代码中却不常见。
#3
0
2 things wrong here:
这里有两件事:
-
AND
is a Boolean operator. You need to use commas to separate multiple columns - You need to group by the account name to get the computed values by account name.
AND是一个布尔运算符。您需要使用逗号分隔多个列
您需要按帐户名称分组才能按帐户名称获取计算值。
So change your query to:
所以将您的查询更改为:
SELECT account_name, SUM(debit)+SUM(credit) AS 'total_balance', SUM(total_balance) AS 'net_revenue'
FROM transaction
GROUP BY account_name
#1
0
Just remove the AND
.
只需删除AND。
SELECT
account_name,
SUM(debit)+SUM(credit) AS 'total_balance',
SUM(total_balance) AS 'net_revenue'
FROM transaction
Note: Although the above query is syntactically valid, SUM
is a group function and you'll probably need some GROUP BY
clause to select the account_name
correctly. Something like this:
注意:虽然上面的查询在语法上是有效的,但SUM是一个组函数,您可能需要一些GROUP BY子句才能正确选择account_name。像这样的东西:
SELECT
account_name,
SUM(debit)+SUM(credit) AS 'total_balance',
SUM(total_balance) AS 'net_revenue'
FROM transaction
GROUP BY account_name
#2
0
No, it is not valid SQL. Use commas to separate columns in the select-list.
不,它不是有效的SQL。使用逗号分隔选择列表中的列。
SELECT account_name ,SUM(debit)+SUM(credit) AS 'total_balance',
SUM(total_balance) AS 'net_revenue'
FROM transaction
The formation of list like apples, bananas and plums
is common in natural English language, but not in code.
苹果,香蕉和李子等列表的形成在自然英语中很常见,但在代码中却不常见。
#3
0
2 things wrong here:
这里有两件事:
-
AND
is a Boolean operator. You need to use commas to separate multiple columns - You need to group by the account name to get the computed values by account name.
AND是一个布尔运算符。您需要使用逗号分隔多个列
您需要按帐户名称分组才能按帐户名称获取计算值。
So change your query to:
所以将您的查询更改为:
SELECT account_name, SUM(debit)+SUM(credit) AS 'total_balance', SUM(total_balance) AS 'net_revenue'
FROM transaction
GROUP BY account_name