I’m trying to set up the best basketball team for fantasy basketball in the 2020-2021 season. I created a database for basketball player’s stats and imported a table that contains projections and draft rankings for this coming season. I’m focusing on players who play in the center position, I have used the IFF function to see if they meet a higher stat in a specific category (column). Then what I would like to do is COUNT the number of ‘YES’ in each row. I want to create another column that adds the values that contains ‘YES’ from each row. Would like to know how to make this possible.
x
SELECT [Player]
, [Position]
, [Team]
, IIF ( [MIN] > 20.83 , 'YES' , 'NO' ) AS 'MIN'
, IIF ( [GP] > 70.7 , 'YES' , 'NO' ) AS 'GP'
, IIF ( [FG%] > 0.51 , 'YES' , 'NO' ) AS 'FG%'
, IIF ( [REB] > 6.5 , 'YES' , 'NO' ) AS 'REB'
, IIF ( [BLK] > 0.91 , 'YES' , 'NO' ) AS 'BLK'
, IIF ( [STL] > 0.52 , 'YES' , 'NO' ) AS 'STL'
, IIF ( [TO] < 1.34 , 'YES' , 'NO' ) AS 'TO'
,
FROM [ProFantasy].[Basketball]
WHERE [Position] LIKE '%C%';
Advertisement
Answer
Perhaps you could try adding them manually along with the if statements.
SELECT [Player]
, [Position]
, [Team]
, IIF ( [MIN] > 20.83 , 'YES' , 'NO' ) AS 'MIN'
, IIF ( [GP] > 70.7 , 'YES' , 'NO' ) AS 'GP'
, IIF ( [FG%] > 0.51 , 'YES' , 'NO' ) AS 'FG%'
, IIF ( [REB] > 6.5 , 'YES' , 'NO' ) AS 'REB'
, IIF ( [BLK] > 0.91 , 'YES' , 'NO' ) AS 'BLK'
, IIF ( [STL] > 0.52 , 'YES' , 'NO' ) AS 'STL'
, IIF ( [TO] < 1.34 , 'YES' , 'NO' ) AS 'TO'
, IIF ( [MIN] > 20.83 , 1 , 0 ) +
IIF ( [GP] > 70.7 , 1 , 0 ) +
IIF ( [FG%] > 0.51 , 1 , 0 ) +
IIF ( [REB] > 6.5 , 1 , 0 ) +
IIF ( [BLK] > 0.91 , 1 , 0 ) +
IIF ( [STL] > 0.52 , 1 , 0 ) +
IIF ( [TO] < 1.34 , 1 , 0 ) AS 'Yes Counts'
FROM [ProFantasy].[Basketball]
WHERE [Position] LIKE '%C%';