>日期参数mysql

时间:2016-03-23 14:01:37

标签: mysql sqlyog

我正在尝试根据当天创建一个拉取的查询。我不知道WHERE中的参数,目前,我将日期用作字符串。

SELECT`u.firstname AS `user`,COUNT(acc.submit_dt) AS `submitted`
FROM asset_camera_check AS acc JOIN users u ON u.userid = acc.user_id 
WHERE(acc.submit_dt = currentdate AND 
      acc.submit_dt < '2016-3-23 6:00:00'GROUP BY u.userid

1 个答案:

答案 0 :(得分:0)

你的WHERE子句需要一个右括号(或者只是去掉左括号 - 你不需要括号)。

除了语法之外,如果您尝试做的是在00:00(包括)和06:00(不包括)之间包含&#34;今天&#34;的记录,请尝试以下内容:

SELECT
  u.firstname AS `user`,
  COUNT(acc.submit_dt) AS `submitted`
FROM asset_camera_check AS acc
JOIN users u ON u.userid = acc.user_id
WHERE acc.submit_dt >= current_date
  AND acc.submit_dt < current_date + interval 6 hour
GROUP BY u.userid