To sum two columns in SQL, you can use the SELECT statement along with the SUM function. Here's an example SQL query:
SELECT column1, column2, SUM(column1 + column2) AS total
FROM table_name;
In this example, column1 and column2 are the columns you want to sum, and
table_name is the name of the table where these columns are located. The SUM(column1 + column2) part of the
query calculates the sum of the two columns for each row, and the AS total part creates an alias for the new
column that contains the sum.
You can also add other columns to the SELECT statement if you want to
retrieve additional information about each row in the table. Here's an example that includes three
columns:
SELECT column1, column2, column3, SUM(column1 + column2) AS total
FROM table_name;
In this example, column3 is another column in the table that you want to
include in the results.
Keep in mind that the data types of the two columns you want to sum
should be compatible. For example, if one column is a string and the other is a number, you will need to
convert the string to a number before adding the two columns together. You can do this using the CAST or
CONVERT functions in SQL.