Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Can we use aggregate function in an aggregate func

Author  Topic 

ikhuram
Starting Member

28 Posts

Posted - 2004-06-01 : 07:06:22
Can I use to calculate
‘Bin1_Pct’ = SUM(CASE binnumber WHEN 1 THEN (numberofparts/COUNT(numberofparts) * 100) END)

ALSO Tell me how to do this if could not be done like this.

select lot.lot_id, lot.program_name, wafer.wafer_id, 'Bin1' = sum( CASE binnumber WHEN 1 THEN numberofparts END), 'Bin1_Color' = SUM( CASE binnumber WHEN 1 THEN user_bin_definition.bin_color END), ‘Bin1_Pct’ = SUM(CASE binnumber WHEN 1 THEN (numberofparts/COUNT(numberofparts) * 100) END), 'Bin2' = sum( CASE binnumber WHEN 2 THEN numberofparts END), 'Bin2_Color' = SUM( CASE binnumber WHEN 2 THEN user_bin_definition.bin_color END), from lot JOIN wafer ON lot.lot_sequence = wafer.lot_sequence JOIN bin_summary ON wafer.wafer_sequence = bin_summary.wafer_sequence LEFT JOIN user_test_program ON lot.program_name = user_test_program.program_name LEFT JOIN user_bin_definition ON user_test_program.prog_id = user_bin_definition.prog_id and bin_summary.binnumber = user_bin_definition.bin_number WHERE bin_summary.binrecordtype = 's' GROUP BY lot.lot_id, lot.program_name, wafer.wafer_idorder by lot.lot_sequence

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2004-06-01 : 07:51:37
why are you asking us? Try it!

note that you should not have single quotes around the column names, nor a comma after the last column in the select list.

- Jeff
Go to Top of Page
   

- Advertisement -