MySQL/达梦/postgreSQL查询昨天的数据
- MySQL/达梦
//两者区别在于,达梦若时间字段为关键字时需要加双引号(关键字,不加双引号字段名会变成大写,若大小写不敏感且非输出字段时可忽略)
SELECT * from continuousalarm where TO_DAYS( NOW( ) ) - TO_DAYS(时间字段) = 1
//时间字段为 Date
//mysql
TO_DAYS( NOW( ) ) - TO_DAYS(Date) = 1
//达梦
TO_DAYS( NOW( ) ) - TO_DAYS("Date") = 1
- postgreSQL
时间字段类型为 timestamp
SELECT * from continuousalarm WHERE to_date("Date",'YYYY-MM-DD') = current_date - 1
参考 :https://blog.csdn.net/qq_32157851/article/details/88852386