如何从2个时间表中获取所选时间?

时间:2018-10-12 00:42:32

标签: mysql sql

我试图从用户选择的时间中获取所有数据。例如,我选择 10:00 AM ,我有2个表(start_shift和end_shift)。

start_shift-9:00 AM(VARCHAR)

end_shift-12:30 PM(VARCHAR)

这是我的查询

SELECT * FROM `users` tbl1 LEFT JOIN user_sched tbl2
ON tbl1.uid=tbl2.uid AND TIME(tbl2.start_shift) > TIME('10:00 AM') AND 
TIME(tbl2.end_shift) < TIME('10:00 AM')
WHERE tbl2.sched_day = 'monday'
GROUP BY tbl1.uid

仍然为我带来了空值

Users Table
uid | fname  | lname
1   | Robert | Downy
2   | Jorge  | Dee

User Sched Table
sid | sched_day| start_shift | end_shift | uid
1   | monday   | 09:00 AM    | 12:30 PM  | 1
2   | monday   | 01:30 PM    | 05:30 PM  | 2

1 个答案:

答案 0 :(得分:1)

我认为MySQL不注意“ AM”。更重要的是,您的情况朝错误的方向发展。我想你打算:

Traceback (most recent call last):   File "test1.py", line 1, in
<module>
    import psycopg2   File "/Users/xxx/Library/Python/2.7/lib/python/site-packages/psycopg2/__init__.py",
line 50, in <module>
    from psycopg2._psycopg import (                     # noqa ImportError:
dlopen(/Users/xxx/Library/Python/2.7/lib/python/site-packages/psycopg2/_psycopg.so,
2): Symbol not found: _PQbackendPID   Referenced from:
/Users/xxx/Library/Python/2.7/lib/python/site-packages/psycopg2/_psycopg.so
Expected in: flat namespace  in
/Users/eyabadal/Library/Python/2.7/lib/python/site-packages/psycopg2/_psycopg.so

SELECT * FROM users u LEFT JOIN user_sched us ON u.uid = us.uid AND TIME(us.start_shift) < TIME('10:00:00') AND TIME(us.end_shift) > TIME('10:00:00') AND us.sched_day = 'monday'; GROUP BY只是没有意义。如果要汇总行,通常会使用汇总函数。