views:

47

answers:

1

Four column table - id (int), double1 (bit), double2 (bit), score (int)

Want to write a query the returns the SUM() of the score column, grouped by id, where each row score can be changed based on the two double columns. So if the score is 10 and double1 and/or double2 columns are true, the row score is doubled once or twice.

+6  A: 
SELECT id, SUM(score * (double1 + 1) * (double2 + 1))
FROM tbl
GROUP BY id

(Edited as explicit cast not required. int has higher precedence)

Martin Smith
+1 - Clever! I was going to suggest CASE but I like this more.
JNK
Clever, works like a charm.
coding4cats