Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 日期类型中的按问题排序_Mysql - Fatal编程技术网

Mysql 日期类型中的按问题排序

Mysql 日期类型中的按问题排序,mysql,Mysql,与“2011年1月1日”和“2011年1月31日”之间的日期格式相同(支出日期,%d-%m-%Y) 此外,我无法检查介于、?之间的状态 ExpenditureDate—日期类型 下面的查询显示正确,最新日期将依次出现在顶部 SELECT ExpenditureName,ExpenditureAmount,ExpenditurePlaceTypeWhome,ExpenditureDate FROM tblexpenditure WHERE Status=1 AND EntryUser=2 ORDE

与“2011年1月1日”和“2011年1月31日”之间的日期格式相同(支出日期,%d-%m-%Y)

此外,我无法检查介于、?之间的状态

ExpenditureDate—日期类型

下面的查询显示正确,最新日期将依次出现在顶部

SELECT ExpenditureName,ExpenditureAmount,ExpenditurePlaceTypeWhome,ExpenditureDate FROM tblexpenditure WHERE Status=1 AND EntryUser=2 ORDER BY ExpenditureDate DESC 
但是如果我添加日期格式(ExpertiTureDate,“%d-%m-%Y”)作为ExpertiTureDate

然后松开我的正确顺序,它显示有序

SELECT ExpenditureName,ExpenditureAmount,ExpenditurePlaceTypeWhome,date_format(ExpenditureDate,'%d-%m-%Y') as ExpenditureDate FROM tblexpenditure WHERE Status=1 AND EntryUser=2 ORDER BY ExpenditureDate DESC

我没有一个运行mysql的框来测试,但我尽量避免将格式化的字符串命名为可显示的“支出日期”,与您排序的相同

我没有一个运行mysql的框来测试,但我尽量避免将格式化的可显示字符串命名为“支出日期”,与您排序的相同

MySQL似乎是根据格式化的值排序的。试着写

...,date_format(ExpenditureDate,'%d-%m-%Y') as FormattedExpenditureDate ...

但是将列名称保留在
ORDER BY
子句中。

MySQL似乎按照格式化的值排序。试着写

...,date_format(ExpenditureDate,'%d-%m-%Y') as FormattedExpenditureDate ...

但是将列名称保留在
ORDER BY
子句中。

它们可能是按日期的字典顺序排序的,而不是按时间顺序排序的。这是正常的,因为您使用ExpertiTureDate别名进行排序,该别名是一个包含格式化日期的字符串。 使用其他别名:

SELECT ExpenditureName,ExpenditureAmount,ExpenditurePlaceTypeWhome,date_format(ExpenditureDate,'%d-%m-%Y') as FormattedExpenditureDate FROM tblexpenditure WHERE Status=1 AND EntryUser=2 ORDER BY ExpenditureDate DESC
如果确实要保留相同的别名,还可以尝试以下方法:

SELECT ExpenditureName,ExpenditureAmount,ExpenditurePlaceTypeWhome,date_format(ExpenditureDate,'%d-%m-%Y') as ExpenditureDate FROM tblexpenditure WHERE Status=1 AND EntryUser=2 ORDER BY tblexpenditure.ExpenditureDate DESC

它们可能是按日期的字典顺序排列的,而不是按时间顺序排列的。这是正常的,因为您使用ExpertiTureDate别名进行排序,该别名是一个包含格式化日期的字符串。 使用其他别名:

SELECT ExpenditureName,ExpenditureAmount,ExpenditurePlaceTypeWhome,date_format(ExpenditureDate,'%d-%m-%Y') as FormattedExpenditureDate FROM tblexpenditure WHERE Status=1 AND EntryUser=2 ORDER BY ExpenditureDate DESC
如果确实要保留相同的别名,还可以尝试以下方法:

SELECT ExpenditureName,ExpenditureAmount,ExpenditurePlaceTypeWhome,date_format(ExpenditureDate,'%d-%m-%Y') as ExpenditureDate FROM tblexpenditure WHERE Status=1 AND EntryUser=2 ORDER BY tblexpenditure.ExpenditureDate DESC