sql语法

30 阅读1分钟

oralce

//nvl(x,0)    如果查找到的x為null,就返回0
//sum()    配合group by 使用,將()內的數據相加
//round()    將保留兩位小數,如果沒有兩位就不保留
//mecode(x, case1, value1, case2,value2,value3)    判斷:
SELECT oba03,
   ROUND(SUM(NVL(msb05 * ecb21 *
                 DECODE(ecb13, '1', 1 / 3600, '2', 1 / 60, 1),
                 0)),
         2) plantime,
   ROUND(SUM(NVL(msb08 * ecb21 *
                 DECODE(ecb13, '1', 1 / 3600, '2', 1 / 60, 1),
                 0)),
         2) outtime
  FROM msb_file, ecb_file, oba_file
 WHERE msb03 = ecb01
   AND ecb02 = oba01