select * from checkinout as c
where hour(checkTime)<12 and c.userId in(select b.userid from ....)
group by day(checkTime) ,c.userId order by c.checkTime asc
上面的语句的意思是说查询每个人当天12点以前第一条打卡的记录,
现在出现的问题是,只要in()里面的值记录少于等于15条的时候,就能正常,但是一旦大于15条记录后,就会有问题出现。
所以觉得很诡异。。。
手动添加了具体的值in(1,2,3,4,5,6...15)这样的话就正确,
但是一到了总数16条后,有些记录就会不正确。。可以告诉我为什么吗?
有遇见过这样的问题的吗?
14 个解决方案
#1
果然诡异,你发帖选错论坛了。应该到MySQL/Postgresql去提问...我解决不了你的问题,期待高手
#2
你理解这个 in 的用法没有啊!
select * from checkinout 这个查询的总记录数有没有超过15 条。。
select * from checkinout 这个查询的总记录数有没有超过15 条。。
#3
select * from checkinout as c
where hour(checkTime)<12 and c.userId in(select b.userid from ....)
group by day(checkTime) ,c.userId order by c.checkTime asc
上面的*表示了哪些字段??
因为你后面分组了,此处的*中要么是组函数,要么包含分组的字段,其他分分组或没有使用组函数的字段不能够包含在select子句中。
#4
会不会跟oracle一样,使用in的时候,里面不能超过1000字符,会不会类似
#5
select 后面跟分组字段或者聚合函数或者*,因为我查的是一张表。。
按照天数来查。。我的意思是说。c.userId in(这里要是超过15条记录就会不准确)
我的意思是这样子的
所以我觉得无语了。对这个东西in()里面查的是userID
#6
出来的结果比如说我在c.userid in(34)这样的话就会取到有一条记录是 34 2010-07-05 7:45:30的记录
但是要是c.userId in(这里要是超过15个的话。。) 出来的记录就会显示 34 2010-07-05 9:46:00
所以我觉得很奇怪。。
我反复测试了许多遍了
但是要是c.userId in(这里要是超过15个的话。。) 出来的记录就会显示 34 2010-07-05 9:46:00
所以我觉得很奇怪。。
我反复测试了许多遍了
#7
select * from checkinout as c
where hour(checkTime)<12 and c.userId in(select b.userid from ....)
你先执行这一句,看看再说!是否是对的
where hour(checkTime)<12 and c.userId in(select b.userid from ....)
你先执行这一句,看看再说!是否是对的
#8
楼上的。我真正的是select * from checkinout as c
where hour(c.checkTime)<12 and c.userId in(select b.userid from ....) 后面的也是跟别名的
出来的结果有些不正确。因为In里面出来的记录多于15条了
where hour(c.checkTime)<12 and c.userId in(select b.userid from ....) 后面的也是跟别名的
出来的结果有些不正确。因为In里面出来的记录多于15条了
#9
顶上去。。继续等候高手
#10
in --> exists ?
#11
好像没问题、
mysql> select * from checkinout as c
-> where c.userId in(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,1,2,3)
-> group by day(checkTime) ,c.userId order by c.checkTime asc
-> ;
+--------+---------------------+------+
| userId | checkTime | num1 |
+--------+---------------------+------+
| 2 | 2010-07-29 20:43:40 | 2 |
| 3 | 2010-07-29 20:43:45 | 3 |
| 4 | 2010-07-29 20:43:52 | 4 |
| 5 | 2010-07-29 20:43:55 | 5 |
| 6 | 2010-07-29 20:43:59 | 6 |
| 10 | 2010-07-29 20:44:54 | 10 |
| 11 | 2010-07-29 20:44:54 | 11 |
| 12 | 2010-07-29 20:44:54 | 12 |
| 13 | 2010-07-29 20:44:54 | 13 |
| 14 | 2010-07-29 20:44:54 | 14 |
| 15 | 2010-07-29 20:44:54 | 15 |
| 1 | 2010-07-29 20:44:54 | 1 |
| 16 | 2010-07-29 20:44:54 | 16 |
| 7 | 2010-07-29 20:44:54 | 7 |
| 8 | 2010-07-29 20:44:54 | 8 |
| 9 | 2010-07-29 20:44:54 | 9 |
| 17 | 2010-07-29 20:44:55 | 17 |
| 1 | 2010-07-30 20:35:14 | 1 |
+--------+---------------------+------+
18 rows in set (0.00 sec)
mysql> select * from checkinout;
+--------+---------------------+------+
| userId | checkTime | num1 |
+--------+---------------------+------+
| 1 | 2010-07-30 20:35:14 | 1 |
| 1 | 2010-07-30 20:38:59 | 1 |
| 2 | 2010-07-29 20:43:40 | 2 |
| 3 | 2010-07-29 20:43:45 | 3 |
| 3 | 2010-07-29 20:43:48 | 3 |
| 4 | 2010-07-29 20:43:52 | 4 |
| 5 | 2010-07-29 20:43:55 | 5 |
| 6 | 2010-07-29 20:43:59 | 6 |
| 1 | 2010-07-29 20:44:54 | 1 |
| 2 | 2010-07-29 20:44:54 | 2 |
| 3 | 2010-07-29 20:44:54 | 3 |
| 4 | 2010-07-29 20:44:54 | 4 |
| 5 | 2010-07-29 20:44:54 | 5 |
| 6 | 2010-07-29 20:44:54 | 6 |
| 7 | 2010-07-29 20:44:54 | 7 |
| 8 | 2010-07-29 20:44:54 | 8 |
| 9 | 2010-07-29 20:44:54 | 9 |
| 10 | 2010-07-29 20:44:54 | 10 |
| 11 | 2010-07-29 20:44:54 | 11 |
| 12 | 2010-07-29 20:44:54 | 12 |
| 13 | 2010-07-29 20:44:54 | 13 |
| 14 | 2010-07-29 20:44:54 | 14 |
| 15 | 2010-07-29 20:44:54 | 15 |
| 16 | 2010-07-29 20:44:54 | 16 |
| 17 | 2010-07-29 20:44:55 | 17 |
| 1 | 2010-07-29 20:52:50 | 1 |
| 2 | 2010-07-29 20:52:50 | 2 |
| 3 | 2010-07-29 20:52:50 | 3 |
| 4 | 2010-07-29 20:52:50 | 4 |
| 5 | 2010-07-29 20:52:50 | 5 |
| 6 | 2010-07-29 20:52:50 | 6 |
| 7 | 2010-07-29 20:52:50 | 7 |
| 8 | 2010-07-29 20:52:50 | 8 |
| 9 | 2010-07-29 20:52:50 | 9 |
| 10 | 2010-07-29 20:52:50 | 10 |
| 11 | 2010-07-29 20:52:50 | 11 |
| 12 | 2010-07-29 20:52:50 | 12 |
| 13 | 2010-07-29 20:52:50 | 13 |
| 14 | 2010-07-29 20:52:50 | 14 |
| 15 | 2010-07-29 20:52:51 | 15 |
| 16 | 2010-07-29 20:52:51 | 16 |
| 17 | 2010-07-29 20:52:51 | 17 |
+--------+---------------------+------+
42 rows in set (0.00 sec)
mysql>
mysql> select userid,min(checkTime),num1 from checkinout as c
-> where c.userId in(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,1,2,3)
-> group by day(checkTime) ,c.userId order by c.checkTime asc
-> ;
+--------+---------------------+------+
| userid | min(checkTime) | num1 |
+--------+---------------------+------+
| 2 | 2010-07-29 20:43:40 | 2 |
| 3 | 2010-07-29 20:43:45 | 3 |
| 4 | 2010-07-29 20:43:52 | 4 |
| 5 | 2010-07-29 20:43:55 | 5 |
| 6 | 2010-07-29 20:43:59 | 6 |
| 15 | 2010-07-29 20:44:54 | 15 |
| 8 | 2010-07-29 20:44:54 | 8 |
| 16 | 2010-07-29 20:44:54 | 16 |
| 9 | 2010-07-29 20:44:54 | 9 |
| 10 | 2010-07-29 20:44:54 | 10 |
| 11 | 2010-07-29 20:44:54 | 11 |
| 12 | 2010-07-29 20:44:54 | 12 |
| 13 | 2010-07-29 20:44:54 | 13 |
| 1 | 2010-07-29 20:44:54 | 1 |
| 14 | 2010-07-29 20:44:54 | 14 |
| 7 | 2010-07-29 20:44:54 | 7 |
| 17 | 2010-07-29 20:44:55 | 17 |
| 1 | 2010-07-30 20:35:14 | 1 |
+--------+---------------------+------+
18 rows in set (0.00 sec)
#12
当天12点以前第一条
加个top
select top 1 * from checkinout as c
where hour(checkTime)<12 and c.userId in(select top 1 b.userid from ....)
group by day(checkTime) ,c.userId order by c.checkTime asc
加个top
select top 1 * from checkinout as c
where hour(checkTime)<12 and c.userId in(select top 1 b.userid from ....)
group by day(checkTime) ,c.userId order by c.checkTime asc
#13
非常感谢crazylaa
谢谢你给了我灵感。。thinks
谢谢你给了我灵感。。thinks
#14
里面的字符好像的不能超过范围吧!
#1
果然诡异,你发帖选错论坛了。应该到MySQL/Postgresql去提问...我解决不了你的问题,期待高手
#2
你理解这个 in 的用法没有啊!
select * from checkinout 这个查询的总记录数有没有超过15 条。。
select * from checkinout 这个查询的总记录数有没有超过15 条。。
#3
select * from checkinout as c
where hour(checkTime)<12 and c.userId in(select b.userid from ....)
group by day(checkTime) ,c.userId order by c.checkTime asc
上面的*表示了哪些字段??
因为你后面分组了,此处的*中要么是组函数,要么包含分组的字段,其他分分组或没有使用组函数的字段不能够包含在select子句中。
#4
会不会跟oracle一样,使用in的时候,里面不能超过1000字符,会不会类似
#5
select 后面跟分组字段或者聚合函数或者*,因为我查的是一张表。。
按照天数来查。。我的意思是说。c.userId in(这里要是超过15条记录就会不准确)
我的意思是这样子的
所以我觉得无语了。对这个东西in()里面查的是userID
#6
出来的结果比如说我在c.userid in(34)这样的话就会取到有一条记录是 34 2010-07-05 7:45:30的记录
但是要是c.userId in(这里要是超过15个的话。。) 出来的记录就会显示 34 2010-07-05 9:46:00
所以我觉得很奇怪。。
我反复测试了许多遍了
但是要是c.userId in(这里要是超过15个的话。。) 出来的记录就会显示 34 2010-07-05 9:46:00
所以我觉得很奇怪。。
我反复测试了许多遍了
#7
select * from checkinout as c
where hour(checkTime)<12 and c.userId in(select b.userid from ....)
你先执行这一句,看看再说!是否是对的
where hour(checkTime)<12 and c.userId in(select b.userid from ....)
你先执行这一句,看看再说!是否是对的
#8
楼上的。我真正的是select * from checkinout as c
where hour(c.checkTime)<12 and c.userId in(select b.userid from ....) 后面的也是跟别名的
出来的结果有些不正确。因为In里面出来的记录多于15条了
where hour(c.checkTime)<12 and c.userId in(select b.userid from ....) 后面的也是跟别名的
出来的结果有些不正确。因为In里面出来的记录多于15条了
#9
顶上去。。继续等候高手
#10
in --> exists ?
#11
好像没问题、
mysql> select * from checkinout as c
-> where c.userId in(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,1,2,3)
-> group by day(checkTime) ,c.userId order by c.checkTime asc
-> ;
+--------+---------------------+------+
| userId | checkTime | num1 |
+--------+---------------------+------+
| 2 | 2010-07-29 20:43:40 | 2 |
| 3 | 2010-07-29 20:43:45 | 3 |
| 4 | 2010-07-29 20:43:52 | 4 |
| 5 | 2010-07-29 20:43:55 | 5 |
| 6 | 2010-07-29 20:43:59 | 6 |
| 10 | 2010-07-29 20:44:54 | 10 |
| 11 | 2010-07-29 20:44:54 | 11 |
| 12 | 2010-07-29 20:44:54 | 12 |
| 13 | 2010-07-29 20:44:54 | 13 |
| 14 | 2010-07-29 20:44:54 | 14 |
| 15 | 2010-07-29 20:44:54 | 15 |
| 1 | 2010-07-29 20:44:54 | 1 |
| 16 | 2010-07-29 20:44:54 | 16 |
| 7 | 2010-07-29 20:44:54 | 7 |
| 8 | 2010-07-29 20:44:54 | 8 |
| 9 | 2010-07-29 20:44:54 | 9 |
| 17 | 2010-07-29 20:44:55 | 17 |
| 1 | 2010-07-30 20:35:14 | 1 |
+--------+---------------------+------+
18 rows in set (0.00 sec)
mysql> select * from checkinout;
+--------+---------------------+------+
| userId | checkTime | num1 |
+--------+---------------------+------+
| 1 | 2010-07-30 20:35:14 | 1 |
| 1 | 2010-07-30 20:38:59 | 1 |
| 2 | 2010-07-29 20:43:40 | 2 |
| 3 | 2010-07-29 20:43:45 | 3 |
| 3 | 2010-07-29 20:43:48 | 3 |
| 4 | 2010-07-29 20:43:52 | 4 |
| 5 | 2010-07-29 20:43:55 | 5 |
| 6 | 2010-07-29 20:43:59 | 6 |
| 1 | 2010-07-29 20:44:54 | 1 |
| 2 | 2010-07-29 20:44:54 | 2 |
| 3 | 2010-07-29 20:44:54 | 3 |
| 4 | 2010-07-29 20:44:54 | 4 |
| 5 | 2010-07-29 20:44:54 | 5 |
| 6 | 2010-07-29 20:44:54 | 6 |
| 7 | 2010-07-29 20:44:54 | 7 |
| 8 | 2010-07-29 20:44:54 | 8 |
| 9 | 2010-07-29 20:44:54 | 9 |
| 10 | 2010-07-29 20:44:54 | 10 |
| 11 | 2010-07-29 20:44:54 | 11 |
| 12 | 2010-07-29 20:44:54 | 12 |
| 13 | 2010-07-29 20:44:54 | 13 |
| 14 | 2010-07-29 20:44:54 | 14 |
| 15 | 2010-07-29 20:44:54 | 15 |
| 16 | 2010-07-29 20:44:54 | 16 |
| 17 | 2010-07-29 20:44:55 | 17 |
| 1 | 2010-07-29 20:52:50 | 1 |
| 2 | 2010-07-29 20:52:50 | 2 |
| 3 | 2010-07-29 20:52:50 | 3 |
| 4 | 2010-07-29 20:52:50 | 4 |
| 5 | 2010-07-29 20:52:50 | 5 |
| 6 | 2010-07-29 20:52:50 | 6 |
| 7 | 2010-07-29 20:52:50 | 7 |
| 8 | 2010-07-29 20:52:50 | 8 |
| 9 | 2010-07-29 20:52:50 | 9 |
| 10 | 2010-07-29 20:52:50 | 10 |
| 11 | 2010-07-29 20:52:50 | 11 |
| 12 | 2010-07-29 20:52:50 | 12 |
| 13 | 2010-07-29 20:52:50 | 13 |
| 14 | 2010-07-29 20:52:50 | 14 |
| 15 | 2010-07-29 20:52:51 | 15 |
| 16 | 2010-07-29 20:52:51 | 16 |
| 17 | 2010-07-29 20:52:51 | 17 |
+--------+---------------------+------+
42 rows in set (0.00 sec)
mysql>
mysql> select userid,min(checkTime),num1 from checkinout as c
-> where c.userId in(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,1,2,3)
-> group by day(checkTime) ,c.userId order by c.checkTime asc
-> ;
+--------+---------------------+------+
| userid | min(checkTime) | num1 |
+--------+---------------------+------+
| 2 | 2010-07-29 20:43:40 | 2 |
| 3 | 2010-07-29 20:43:45 | 3 |
| 4 | 2010-07-29 20:43:52 | 4 |
| 5 | 2010-07-29 20:43:55 | 5 |
| 6 | 2010-07-29 20:43:59 | 6 |
| 15 | 2010-07-29 20:44:54 | 15 |
| 8 | 2010-07-29 20:44:54 | 8 |
| 16 | 2010-07-29 20:44:54 | 16 |
| 9 | 2010-07-29 20:44:54 | 9 |
| 10 | 2010-07-29 20:44:54 | 10 |
| 11 | 2010-07-29 20:44:54 | 11 |
| 12 | 2010-07-29 20:44:54 | 12 |
| 13 | 2010-07-29 20:44:54 | 13 |
| 1 | 2010-07-29 20:44:54 | 1 |
| 14 | 2010-07-29 20:44:54 | 14 |
| 7 | 2010-07-29 20:44:54 | 7 |
| 17 | 2010-07-29 20:44:55 | 17 |
| 1 | 2010-07-30 20:35:14 | 1 |
+--------+---------------------+------+
18 rows in set (0.00 sec)
#12
当天12点以前第一条
加个top
select top 1 * from checkinout as c
where hour(checkTime)<12 and c.userId in(select top 1 b.userid from ....)
group by day(checkTime) ,c.userId order by c.checkTime asc
加个top
select top 1 * from checkinout as c
where hour(checkTime)<12 and c.userId in(select top 1 b.userid from ....)
group by day(checkTime) ,c.userId order by c.checkTime asc
#13
非常感谢crazylaa
谢谢你给了我灵感。。thinks
谢谢你给了我灵感。。thinks
#14
里面的字符好像的不能超过范围吧!