ALTER TABLE ORDER BY str_to_date 和 time_to_sec
我试图在导入文件后重新排序表,但在此查询中出现 mysql 语法错误:
ALTER TABLE tablename ORDER BY str_to_date(date, '%m/%d/%Y'), time_to_sec(time) ASC
任何人都可以看到此问题吗?这是我收到的错误:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(date, '%m/%d/%Y'), time_to_sec(time) ASC' at line 1
I am trying to re-order a table after importing a file but am getting a mysql syntax error on this query:
ALTER TABLE tablename ORDER BY str_to_date(date, '%m/%d/%Y'), time_to_sec(time) ASC
Can anyone see anything wrong with this? this is the error I am getting:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(date, '%m/%d/%Y'), time_to_sec(time) ASC' at line 1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
根据 mysql 手册,
ALTER TABLE ORDER BY
需要一个 col_name,但您尝试使用函数对其进行排序。我建议创建 2 个新列,用函数结果填充它们,然后按它们排序。
According to mysql manual,
ALTER TABLE ORDER BY
expects a col_name, but you are trying to order it using a function.I suggest create 2 new columns, populate them with function results, and then order by them.
您可能必须为此使用临时表,因为您是按函数排序的。
您可以将第一个语句设置为
CREATE TEMPORARY TABLE
,但是如果您丢失会话,您就会丢失数据。You might have to use a temp table for this since you're ordering by a function.
You could make the first statement a
CREATE TEMPORARY TABLE
, but if you lose your session you lose your data.您是否尝试过
ALTER TABLE tablename ORDER BY date, time ASC
我提到这一点是因为它可能会为您提供所需的顺序。
否则,您需要按照 German Rumm 的建议进行操作,添加具有正确数据类型的列,或者在执行 SQL 时进行排序。
Did you try
ALTER TABLE tablename ORDER BY date, time ASC
I mention this because it might give you the order you need.
Otherwise you'll need to either do as German Rumm suggested, add columns with the correct datatype, or do your ordering when you do your SQL.
我想我解决了这个问题。我将导入的数据存储在临时表中,然后将其移动到永久表中,并且需要先对临时表中的数据进行排序,然后再插入新表。所以我所做的是通过具有 order by 语句的 select 语句插入到新表中。
I think I resolved this issue. I was storing imported data in a temp table before moving it onto it's permanent table and needed to sort the data in the temp table first before inserting into the new table. so what I do instead is insert into the new table via a select statement which has the order by statement.
您使用的是较旧版本的 mysql,
STR_TO_DATE
仅适用于 MySQL 4.1.1 版本。更新MySQL版本。
You are using an older version of mysql,
STR_TO_DATE
is only availabe from version 4.1.1 of MySQL.Update MySQL version.