Prob... puzzle #3.
Short description
Write query that calculates product per group.
Long description (sample data included)
Product of all values in a group = something like SUM but with * instead of +. Lemme illustrate that with sample data:
Expected results are:
Rules & restrictions
- code must work well for ALL numeric values and NULL
- Everything must be done with a single query
- only SQL Server 2000 features are allowed
IMHO this puzzle is too simple to wait for next Friday... shoot immediately.
------
"There's a man... He's bald and wears a short-sleeved shirt, and somehow he's very important to me. I think his name is Homer."
(Jack O'Neill, Stargate)
![[banghead] [banghead] [banghead]](/data/assets/smilies/banghead.gif)
Short description
Write query that calculates product per group.
Long description (sample data included)
Product of all values in a group = something like SUM but with * instead of +. Lemme illustrate that with sample data:
Code:
create table myTable
( groupID varchar(16),
numValue int
)
insert into myTable values ( 'Group 1', 1 )
insert into myTable values ( 'Group 1', 2 )
insert into myTable values ( 'Group 1', 3 )
insert into myTable values ( 'Group 2', 1 )
insert into myTable values ( 'Group 2', -5 )
insert into myTable values ( 'Group 2', 2 )
insert into myTable values ( 'Group 3', 4 )
insert into myTable values ( 'Group 3', 0 )
insert into myTable values ( 'Group 3', 1 )
insert into myTable values ( 'Group 4', -2 )
insert into myTable values ( 'Group 4', -4 )
insert into myTable values ( 'Group 5', 7 )
insert into myTable values ( 'Group 5', NULL )
insert into myTable values ( 'Group 6', NULL )
Code:
groupID groupProduct
-------.-------------
Group1 6
Group2 -10
Group3 0
Group4 8
Group5 7
Group6 NULL
Rules & restrictions
- code must work well for ALL numeric values and NULL
- Everything must be done with a single query
- only SQL Server 2000 features are allowed
IMHO this puzzle is too simple to wait for next Friday... shoot immediately.
------
"There's a man... He's bald and wears a short-sleeved shirt, and somehow he's very important to me. I think his name is Homer."
(Jack O'Neill, Stargate)
![[banghead] [banghead] [banghead]](/data/assets/smilies/banghead.gif)