0
SELECT account_name ,sum(total_balance) from transaction 
where account_name IN('cash','a/r','supplies','prepaid','land','gold')
AS total_assets
ORDER BY account_name

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 'as total_assets order by account_name LIMIT 0, 30' at line 3

Hamlet Hakobyan
  • 32,965
  • 6
  • 52
  • 68
user27852
  • 5
  • 4

3 Answers3

1

remove AS total_assets

SELECT account_name ,sum(total_balance) from transaction 
where account_name IN('cash','a/r','supplies','prepaid','land','gold')
ORDER BY account_name
ashishmaurya
  • 1,196
  • 10
  • 18
1

You have an alias in the wrong place.

SELECT account_name ,sum(total_balance) from transaction 
where account_name IN('cash','a/r','supplies','prepaid','land','gold')
AS total_assets
ORDER BY account_name

should be

SELECT account_name ,sum(total_balance) AS total_assets
from transaction 
where account_name IN('cash','a/r','supplies','prepaid','land','gold')
ORDER BY account_name
John Conde
  • 217,595
  • 99
  • 455
  • 496
0

Move the as total_assets into the select clause. This is used to define a column alias:

select account_name, sum(total_balance) as total_assets
from transaction 
where account_name in ('cash', 'a/r', 'supplies', 'prepaid', 'land', 'gold')
order by account_name;
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786