[英]'NOT GREATER THAN' condition Mysql
I have a mysql table with columns userid
and createdon
where createdon
column has DATE
datatype. 我有一个mysql表,其中包含userid
和createdon
,其中createdon
列具有DATE
数据类型。
---------------------------------------------------------------------------------
ID UserId CreatedOn
1 65 2013-06-13
2 54 2013-07-03
3 34 2013-08-23
4 65 2013-09-13
5 89 2013-09-13
Now I want the userids where last createdon was before 2013-09-08. 现在我想要最后创建的用户标识在2013-09-08之前。 The correct answer will be userids 54,34 正确的答案是用户ID 54,34
Using 运用
select userid from table where createdon <'2013-09-08'
returns 65,54,34 and usind 返回65,54,34和usind
select userid from table where userid notin (select userid from table where createdon > '2013-09-07')
takes a lot of time. 花了很多时间。
How to get the rows where last createdon < 2013-09-08 如何获取最后创建的行<2013-09-08
Your expectation is wrong.
你的期望是错误的。
The first row of the table you posted would meet your criteria (
'2013-06-'13' < '2013-09-08'
).
您发布的表格的第一行符合您的条件(
'2013-06-'13' < '2013-09-08'
)。
So a resultset with
65,54,34
is as expected.
因此
65,54,34
的结果集符合预期。
Misunderstood the question. 误解了这个问题。
What you want is: 你想要的是:
SELECT DISTINCT
UserId
FROM
tbl outerTbl
WHERE NOT EXISTS (
SELECT *
FROM tbl innerTbl
WHERE
outerTbl.UserId = innerTbl.UserId
AND innerTbl.createdOn >= '2013-09-08'
)
Try using STR_TO_DATE()
function 尝试使用STR_TO_DATE()
函数
SELECT userid FROM table
WHERE createdon <= STR_TO_DATE('2013-09-08', '%Y-%m-%d')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.