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.
| Author |
Topic |
|
jpiscit1
Posting Yak Master
130 Posts |
Posted - 2004-03-23 : 16:09:21
|
| Can someone tell me how they might approach this problem: I am running Sigma Yield calculations on values in one table comparing the yield result to another table containing standard 6 sigma yields and Sigma values.For Example:SELECT (1-(@DefectOpp/(SUM(low_lip+high_lip+v_cuts+channel+leakage+torn+bubbles+Other)*(parts_per_sheet*sht_per_stk*No_Stacks_run))))*100 As [Act_Yield] FROM prod_data WHERE (Item_no = 'ISI0246')Group by parts_per_sheet, sht_per_stk, No_Stacks_runTells me what the current yield is based on a 6-sigma calculation. Now i need to look values up in another table and compare it to the closest value found. Here would be an example result set from the query above:Act_Yield97.6470588235294117699.9784946236559139899.4082840236686390599.55555555555555556The other table (tbl_TheSigmaTable) would have values such as:Sigma DPMO Yield3.6 17864.0 98.200003.7 13903.0 98.600003.8 10724.0 98.900003.9 8198.0 99.180004.0 6210.0 99.380004.1 4661.0 99.530004.2 3467.0 99.650004.3 2555.0 99.740004.4 1866.0 99.810004.5 1350.0 99.870004.6 968.0 99.900004.7 687.0 99.931004.8 483.0 99.952004.9 337.0 99.966005.0 233.0 99.977005.1 159.0 99.984005.2 108.0 99.989205.3 72.0 99.992805.4 48.0 99.995205.5 32.0 99.996805.6 21.0 99.997905.7 13.0 99.998665.8 8.5 99.999155.9 5.4 99.999466.0 3.4 99.99966Im looking to compare the value in the first table (Act_Yield) to the value in the second table (Yield) and select the sigma value that is the closest in yield.For example, i would expect these results:Act_Yield Sigma97.64705882352941176 3.599.97849462365591398 599.40828402366863905 499.55555555555555556 4.1Any thoughts on how i might generate a compare statement for this?Thanks!! |
|
|
ditch
Master Smack Fu Yak Hacker
1466 Posts |
Posted - 2004-03-23 : 23:39:19
|
| You can try by finding the min absolute value between the 2 Yield values.I have written some code here, I am not sure how to join these tables so I have assumed the joins can only happen on the yield values where the difference between the 2 is the lowest, this could be very cpu intensive because of the use of the cross join on tbl_TheSigmaTable, I am hoping that this table is rather small - If this is the case then you can perhaps try something like this.--*************************************************************************************SELECT c.Act_Yield, c.Sigma, MIN(c.Yield_Diff) FROM (SELECT a.Act_Yield, b.Sigma, ABS((a.Act_Yield) - b.Yield) as Yield_Diff FROM (SELECT (1-(@DefectOpp/(SUM(low_lip+high_lip+v_cuts+channel+leakage+torn+bubbles+Other)* (parts_per_sheet*sht_per_stk*No_Stacks_run))))*100 As [Act_Yield] FROM prod_data WHERE (Item_no = 'ISI0246') Group by parts_per_sheet, sht_per_stk, No_Stacks_run) a CROSS JOIN tbl_TheSigmaTable b) cGROUP BY c.Act_Yield, c.Sigma--**************************************************************************But i think that the easiest would be to somehow solve it by finding the lowest absolute value per sigmaie MIN(ABS(Yield1 - Yield2))Duane. |
 |
|
|
jpiscit1
Posting Yak Master
130 Posts |
Posted - 2004-03-24 : 08:47:57
|
| Thanks for your input Duane.I have narrowed my query by selecting only one record to make it easier to work with. Note modified WHERE Clause:WHERE (Item_no = 'ISI0246' AND work_order_no = 1203 AND stack_no = 30060)I think your idea is along the right lines. In fact, I modified the query a bit so i can see the actual delta values and this is what i get:Modified Query:Declare @DefectOpp numeric (18,0)Set @DefectOpp = 8SELECT b.Sigma, MIN(ABS((a.Act_Yield) - b.Yield)) as Yield_DiffFROM(SELECT (1-(@DefectOpp/(SUM(low_lip+high_lip+v_cuts+channel+leakage+torn+bubbles+Other)*(parts_per_sheet*sht_per_stk*No_Stacks_run))))*100 As [Act_Yield] FROM prod_data WHERE (Item_no = 'ISI0246' AND work_order_no = 1203 AND stack_no = 30060)Group by parts_per_sheet, sht_per_stk, No_Stacks_run) aCross join tbl_TheSigmaTable bGroup By b.SigmaResults:Sigma Yield_Diff.1 91.0111111111111111.2 89.4111111111111111.3 87.6111111111111111.4 85.5111111111111111.5 83.2111111111111111.6 80.7111111111111111.7 77.9111111111111111.8 74.9111111111111111.9 71.71111111111111111.0 68.21111111111111111.1 64.61111111111111111.2 60.91111111111111111.3 57.01111111111111111.4 53.11111111111111111.5 49.11111111111111111.6 45.11111111111111111.7 41.21111111111111111.8 37.31111111111111111.9 33.61111111111111112.0 30.01111111111111112.1 26.51111111111111112.2 23.31111111111111112.3 20.31111111111111112.4 17.51111111111111112.5 15.01111111111111112.6 12.71111111111111112.7 10.61111111111111112.8 8.81111111111111112.9 7.21111111111111113.0 5.81111111111111113.1 4.61111111111111113.2 3.61111111111111113.3 2.71111111111111113.4 2.01111111111111113.5 1.41111111111111113.6 .91111111111111113.7 .51111111111111113.8 .21111111111111113.9 .06888888888888894.0 .26888888888888894.1 .41888888888888894.2 .53888888888888894.3 .62888888888888894.4 .69888888888888894.5 .75888888888888894.6 .78888888888888894.7 .81988888888888894.8 .84088888888888894.9 .85488888888888895.0 .86588888888888895.1 .87288888888888895.2 .87808888888888895.3 .88168888888888895.4 .88408888888888895.5 .88568888888888895.6 .88678888888888895.7 .88754888888888895.8 .88803888888888895.9 .88834888888888896.0 .8885488888888889Here's what I get with out the sigma column:Query:SELECT MIN(ABS((a.Act_Yield) - b.Yield)) as Yield_DiffFROM(SELECT (1-(@DefectOpp/(SUM(low_lip+high_lip+v_cuts+channel+leakage+torn+bubbles+Other)*(parts_per_sheet*sht_per_stk*No_Stacks_run))))*100 As [Act_Yield] FROM prod_data WHERE (Item_no = 'ISI0246' AND work_order_no = 1203 AND stack_no = 30060)Group by parts_per_sheet, sht_per_stk, No_Stacks_run) aCross join tbl_TheSigmaTable bResults:Yield_Diff.0688888888888889This would imply for this particular record the Sigma value (actually a 6 sigma value) should be 3.9 as per the table above. (1)Im still not sure how I would display this. And (2), I'm not sure how I would handle multiple records if i open the WHERE clause back up to just the item_no.Thoughts??thanks. |
 |
|
|
|
|
|
|
|