I am using T-SQL for a few months and there is one thing I simply don't know how to do. Let's say we have a table created below
DECLARE @table TABLE
(
id int,
status_FK int,
[value] int
)
INSERT INTO @table (id, status_FK, [value])
VALUES (1, 1, 1000),
(2, 1, 2000),
(3, 2, 3000),
(4, 1, 2000),
(5, 2, 2000),
(6, 2, 3000),
(7, 5, 12000)
SELECT
(SELECT SUM(value) WHERE status_FK = 1) AS 'status1',
(SELECT SUM(value) WHERE status_FK = 2) AS 'status2'
FROM
@table
WHERE
value > 1500
What I'm trying to do is use condition value > 1500 for all subqueries but also each subquery have specific condition. Can someone please explain me how to do this simple thing without repeating whole main query in both subqueries with different conditions? Many thanks <3