如何从crontab获得小时并在MySQL中存储时按订单排序?
我有一个装有crontab的菲尔德,现在我想将桌子符合符合crontab小时的桌子,如何编写SQL? 例如,crontab字段是:
7 9 9 */1 * ?,
0 9 8 */1 * ?,
0 9 19 */1 * ?;
我希望结果是
0 9 8 */1 * ?,
7 9 9 */1 * ?,
0 9 19 */1 * ?;
现在我只能像这样写SQL:
select * from tb_student order by crontab desc
I have a feild that store crontab ,now I want to sort the tablee accordring to the crontab hour,how to write the sql?
For example,the crontab field is :
7 9 9 */1 * ?,
0 9 8 */1 * ?,
0 9 19 */1 * ?;
I want the result is
0 9 8 */1 * ?,
7 9 9 */1 * ?,
0 9 19 */1 * ?;
Now I can only write the sql like this:
select * from tb_student order by crontab desc
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因为
seconds
不可用于crontab表达式,并且可能有一些特殊字符,如表。* /, - < / code>
* /, - < / code>
* /, - < / < / < / < /代码>
* /, - L W < / code>
* /, - < / code>
* /, - l#< / code>
如果我们确保小时为数字且格式一样。
我们可以尝试使用
substring_index
获得您的预期订单号。sqlfiddle
IMHO, I would create a column to store a value which can create索引并改善性能,如果您想使用该订单或过滤条件,而不是 crontab列的
订单。
Because
Seconds
is not Mandatory for crontab expression and there might be some Special characters as below tables.* / , -
* / , -
* / , -
* / , - L W
* / , -
* / , - L #
* / , -
if we make sure the hour will be number and as same format.
We can try to use
SUBSTRING_INDEX
to get part of your expect order number.sqlfiddle
IMHO, I would create a column to store a value which can create an index and improve the performance if your want to use that be order or filter condition instead of
order by
crontab column.