当前位置: 代码迷 >> Oracle开发 >> sql有关问题。求解答~
  详细解决方案

sql有关问题。求解答~

热度:73   发布时间:2016-04-24 07:03:14.0
sql问题。。。。求解答~!!!!急啊~~~~~
SELECT Q.NAME DEVICE_NAME,T.NAME T_NAME,B.AVE,B.SD,SUM(CASE WHEN D.OUT_OF_CONTROL=1 THEN 1 ELSE 0 END)OUT_OF_CONTROL_TIME, COUNT(D.ID)TEST_TIME,D.TEST_ID,B.Batch_No,
         POWER(AVG(CASE WHEN D.ISCALPOINT=0 THEN POWER(D.TEST_VAL-SSS,2)ELSE NULL END),0.5),
         AVG(CASE WHEN D.ISCALPOINT=0 THEN D.TEST_VAL WHEN D.ISCALPOINT IS NULL THEN D.TEST_VAL ELSE NULL END)SSS         FROM QC_QCTEST_DATA D,QC_TEST T,QC_DEVICE Q,QC_QCTEST_BATCH B 
         WHERE D.DEV_ID=1715
         AND TO_CHAR(D.TEST_DATE_TIME,'yyyy-MM')='2013-05'
         AND B.TYPE=2
         AND D.BATCH_ID=B.ID
         AND D.DEV_ID=Q.ID
         AND D.TEST_ID=T.ID 
         GROUP BY D.TEST_ID,Q.NAME,T.NAME,B.AVE,B.SD,B.TYPE,B.Batch_No
 


怎么写可以将下面红色SSS内容加到上面红色的位置进行计算???现在sql语句是错的 
SQL select

------解决方案--------------------
这样试试 


SELECT Q.NAME DEVICE_NAME,T.NAME T_NAME,B.AVE,B.SD,
       SUM(DECODE(D.OUT_OF_CONTROL,1,1,0)) OUT_OF_CONTROL_TIME, 
       COUNT(D.ID)TEST_TIME,
       D.TEST_ID,B.Batch_No,
       POWER(AVG(DECODE(D.ISCALPOINT,0,POWER(D.TEST_VAL-AVG(DECODE(NVL(D.ISCALPOINT,0),0,D.TEST_VAL,NULL))),2))),0.5),
       AVG(DECODE(NVL(D.ISCALPOINT,0),0,D.TEST_VAL,NULL)) SSS         
FROM QC_QCTEST_DATA D,QC_TEST T,QC_DEVICE Q,QC_QCTEST_BATCH B 
WHERE D.DEV_ID=1715
         --AND TO_CHAR(D.TEST_DATE_TIME,'yyyy-MM')='2013-05'
         AND D.TEST_DATE_TIME >= TO_DATE('2013-05','YYYY-MM') 
         and D.TEST_DATE_TIME < ADD_MONTHS(TO_DATE('2013-05','YYYY-MM'),1)
         AND B.TYPE=2
         AND D.BATCH_ID=B.ID
         AND D.DEV_ID=Q.ID
         AND D.TEST_ID=T.ID 
         GROUP BY D.TEST_ID,Q.NAME,T.NAME,B.AVE,B.SD,B.TYPE,B.Batch_No
  相关解决方案