次の形式で、SUM()
3つの同様の条件で操作を実行しようとしています。if()
最初の1つ:
if((TIME_TO_SEC(TIMEDIFF(IF(TIME = '0000-00-00 00:00:00',sysdate() , TIME ), TIME2)) > high OR TIME IS NULL) AND TIME3 != '0000-00-00 00:00:00' AND DATE_FORMAT(TIME2, '%Y-%m-%d %H:%i') < DATE_FORMAT(now(), '%Y-%m-%d %H:%i')
二つ目:
if(TIME_TO_SEC(TIMEDIFF(IF(TIME = '0000-00-00 00:00:00',sysdate() , TIME ), TIME2)) > value AND TIME3 != '0000-00-00 00:00:00' AND DATE_FORMAT(TIME2, '%Y-%m-%d %H:%i') < DATE_FORMAT(now(), '%Y-%m-%d %H:%i')
三つ目:
if(TIME_TO_SEC(TIMEDIFF(IF(TIME = '0000-00-00 00:00:00',sysdate() , TIME ), TIME2)) >0 AND TIME3 != '0000-00-00 00:00:00' AND DATE_FORMAT(TIME2, '%Y-%m-%d %H:%i') < DATE_FORMAT(now(), '%Y-%m-%d %H:%i')
存在high
とvalue
、いくつかのテーブルの2つの異なるフィールド列。
残念ながら、私はこれを機能させることができないようです。おそらく、この文をSUM()
一緒に作成できないためです。
これはどのように行うことができますか?
編集:クエリ全体を追加しました:
SELECT VALUE1 ,
COUNT( * ) TOTAL
from (
SELECT (
if((TIME_TO_SEC(TIMEDIFF(IF(TIME = '0000-00-00 00:00:00',sysdate() , TIME ), TIME2)) > high OR TIME IS NULL) AND TIME3 != '0000-00-00 00:00:00' AND DATE_FORMAT(TIME2, '%Y-%m-%d %H:%i') < DATE_FORMAT(now(), '%Y-%m-%d %H:%i')) +
if(TIME_TO_SEC(TIMEDIFF(IF(TIME = '0000-00-00 00:00:00',sysdate() , TIME ), TIME2)) > value AND TIME3 != '0000-00-00 00:00:00' AND DATE_FORMAT(TIME2, '%Y-%m-%d %H:%i') < DATE_FORMAT(now(), '%Y-%m-%d %H:%i')) +
if(TIME_TO_SEC(TIMEDIFF(IF(TIME = '0000-00-00 00:00:00',sysdate() , TIME ), TIME2)) >0 AND TIME3 != '0000-00-00 00:00:00' AND DATE_FORMAT(TIME2, '%Y-%m-%d %H:%i') < DATE_FORMAT(now(), '%Y-%m-%d %H:%i'))) as 'ok',
if((TIME_TO_SEC(TIMEDIFF(IF(TIME = '0000-00-00 00:00:00',sysdate() , TIME ), TIME2)) > high OR TIME IS NULL) AND DATE_FORMAT(TIME2, '%Y-%m-%d %H:%i') < DATE_FORMAT(now(), '%Y-%m-%d %H:%i'),4,
if(TIME_TO_SEC(TIMEDIFF(IF(TIME = '0000-00-00 00:00:00',sysdate() , TIME ), TIME2)) > value AND DATE_FORMAT(TIME2, '%Y-%m-%d %H:%i') < DATE_FORMAT(now(), '%Y-%m-%d %H:%i'),3,
if(TIME_TO_SEC(TIMEDIFF(IF(TIME = '0000-00-00 00:00:00',sysdate() , TIME ), TIME2)) >0 AND DATE_FORMAT(TIME2, '%Y-%m-%d %H:%i') < DATE_FORMAT(now(), '%Y-%m-%d %H:%i'),2,
if(TIME >'0000-00-00 00:00:00', 1,0) ))) VALUE1
FROM table1 , table2 left outer join table3 on( value2 = value3 ) where id_param='col1' and col2 = DATE_FORMAT(if(CURTIME()>='00:00:00' and CURTIME() < '08:00:00',sysdate() - INTERVAL 1 DAY, sysdate()), '%Y-%m-%d') ) as datos GROUP BY VALUE1
これにより、「ok」、「4」、「3」、および「2」の値を持つ2columnx3rowsテーブルが返されます。