Today my problem is this I have 2 columns and I wish to check if the sum of those columns isn’t bigger than a value (485 for example) and if is do a query…
I though to do
SELECT * FROM table WHERE ColumnA + ColumnB < 485
But it isn’t working… I’ve already tried with
SELECT Sum(ColumnA) + Sum(ColumnB) AS Total FROM table
but it gives me 1 column with the sum of all rows, I instead want a row for every sum. So how can I do..? xD I hope you understood if not just ask that I try to explain it better! and thanks in advance for those who will help me!
EDIT: I Found out XD the problem was that the columns was Smallint and the result of 1 or more rows was more than 32k so it wasn’t working! Thanks all!!
The right query to achieve it is:
This way the
Selectwill return all the rows where ColumnA + ColumnB is less than 485If otherwise you want in return the sum of the two columns you can use
This way the query do a sum of columnA on all the rows, the sum of ColumnB on all the rows and then sum the two sums…