• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

simple SQL questions

SONYFX

Senior member

If I have a table like below with three columns:

ID Total1 Total2
---------------------------------
1 10 20
2 15 5


How do I write a SQL query so that it returns (add up columns in every row):


ID Total
-----------------------
1 30
2 20
 
if the total columns are not char:
select ID, Total1+Total2 as Total from <tablename>

select ID, sum(total1, total2) as Total from <tablename>

Those work in MSSQL, probably very similar in mysql.

 
Originally posted by: WannaFly
if the total columns are not char:
select ID, Total1+Total2 as Total from <tablename>

select ID, sum(total1, total2) as Total from <tablename>

Those work in MSSQL, probably very similar in mysql.


I tried and it gives me an error: "invalid number of arguments"
 
That first statement Wannafly gave was straight ANSI SQL, that should work in just about any database. Give us your exact query, you probably have an extra comma somewhere.
 
Back
Top