I need to sum all values VALUEX found by select with three where clauses, like this:
SELECT //sum all VALUEX found (will be a list) and sum this result with a value passed by user (I am using JDBCTemplate to create the query and set parameters) //compare this sum with the first VALUEY found ordered by COLUMNCLAUSEORDER, in case the sum is greater return true, else false WHERE VALUECLAUSEONE = 'somestring' AND VALUECLAUSETWO = 'otherstring' AND VALUECLAUSETHREE IN ('40', '20') ORDER BY COLUMNCLAUSEORDER``` Columns data types: VALUEX decimal(9, 2) VALUEY decimal(9, 2) VALUECLAUSEONE string VALUECLAUSETWO string VALUECLAUSETHREE string COLUMNCLAUSEORDER integer I tried to use CASE WHEN, and other aproaches, but unsuccesfully :( Please, any ideas? PS: It's for work purposes, so I can't write it as a procedure https://stackoverflow.com/questions/66739477/sql-how-to-create-a-query-that-sum-a-column-a-compare-with-the-max-value-of-a March 22, 2021 at 10:07AM
没有评论:
发表评论