选择生日在本周(周一至周日)的所有用户

时间:2016-07-15 15:26:54

标签: mysql

我正在尝试显示生日在本周(周一至周日)内的所有用户。在搜索到处后,我能够得到这个,但它也显示了上周和本周的用户。

SELECT * FROM teachers WHERE WEEK(birthday, 0) = WEEK(NOW(), 0)

3 个答案:

答案 0 :(得分:1)

更改3函数的第二个参数。我认为您希望它为50。根据文档。

将模式设置为Traceback (most recent call last): File "/usr/share/gdb/auto-load/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21-gdb.py", line 64, in <module> register_libstdcxx_printers(gdb.current_objfile()) File "/usr/lib/x86_64-linux-gnu/../../share/gcc-5/python/libstdcxx/v6/__init__.py", line 33, in register_libstdcxx_printers register_libstdcxx_xmethods(obj) File "/usr/lib/x86_64-linux-gnu/../../share/gcc-5/python/libstdcxx/v6/xmethods.py", line 600, in register_libstdcxx_xmethods gdb.xmethod.register_xmethod_matcher(locus, ArrayMethodsMatcher()) File "/usr/share/gdb/python/gdb/xmethod.py", line 266, in register_xmethod_matcher index = _lookup_xmethod_matcher(locus, matcher.name) File "/usr/share/gdb/python/gdb/xmethod.py", line 236, in _lookup_xmethod_matcher for i in range(0, len(locus.xmethods)): AttributeError: 'gdb.Objfile' object has no attribute 'xmethods' 会根据您在问题中所说的内容,让上周星期日生日的人过来。

Screenshot of table of mode values

https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_week

答案 1 :(得分:0)

检查MySQL的功能WEEKOFYEAR。您可以像这样使用它来让用户在本周获得生日:

MERGE INTO dim_trading_accounts
  USING master_customer
    ON dim_trading_accounts.trading_code = upper(master_customer.mcust_code)
WHEN MATCHED THEN
  UPDATE
    SET dim_trading_accounts.gpid = master_customer.gpid;

答案 2 :(得分:0)

使用函数WEEKOFYEAR

SELECT * FROM teachers WHERE WEEKOFYEAR(birthday) = WEEKOFYEAR(NOW());

WEEKOFYEAR会返回1到53之间的数字。