2012-11-30 67 views
0
SELECT `Item`.`name`, DATE_SUB(Item.modified, INTERVAL 1 DAY), 
CASE 
    WHEN DATE_SUB(Item.modified, INTERVAL 1 DAY) > Item.modified 
    THEN 'FALSE' 
    ELSE 'TRUE' 
END status, `Item`.`restaurant_id` FROM `fs_development`.`items` AS `Item` 
WHERE `Item`.`restaurant_id` = (677) 
ORDER BY `modified` DESC LIMIT 1 

我希望有一個狀態字段,其中'TRUE'或'FALSE'表示記錄是否在一天內更新。白天更新的記錄

到目前爲止,上述工作尚未開始。

回答

0
SELECT `Item`.`name`, 
     DATE_SUB(Item.modified, INTERVAL 1 DAY), 
     CASE WHEN date(Item.modified) = curdate() 
      THEN 'TRUE' 
      ELSE 'FALSE' 
     END status, 
     `Item`.`restaurant_id` 
FROM `fs_development`.`items` AS `Item` 
WHERE `Item`.`restaurant_id` = (677) 
ORDER BY `modified` DESC 
LIMIT 1