gpt4 book ai didi

mysql - 我无法使用 ORDER BY(日期类型)

转载 作者:行者123 更新时间:2023-11-30 23:25:20 25 4
gpt4 key购买 nike

我正在尝试按日期类型字段名称为 dDate(格式示例为 2008-12-26)进行排序,但它不起作用有人可以告诉我我做错了什么请。

    $listsql = "SELECT contact.id, CONCAT(lastname,', ',firstname) AS fullname, lastname, firstname,
dDate, line1, line2, city, state, zip, phone1, phone2, country, whoAdded
FROM ". TABLE_CONTACT ." AS contact
LEFT JOIN ". TABLE_ADDRESS. " AS address ON contact.id=address.id AND contact.primaryAddType=address.type
LEFT JOIN ". TABLE_EMAIL ." AS email ON contact.id=email.id AND contact.primaryAddType=email.type
WHERE contact.hidden != 1
ORDER BY email.dDate DESC";

它没有给出任何错误或任何它只是没有排列日期我希望它有日期排列 DESC 或 ASC 无关紧要例如:

2008-12-26
2008-12-27
2008-12-28

2008-12-28
2008-12-27
2008-12-26

我得到了这样的东西

2012-11-16
2012-11-30
2012-11-26
2012-11-30

SQL 输出是:

mysql> show create table address_email;
+---------------+---------------------------------------------------------------
--------------------------------------------------------------------------------
-------------------------+
| Table | Create Table

|
+---------------+---------------------------------------------------------------
--------------------------------------------------------------------------------
-------------------------+
| address_email | CREATE TABLE `address_email` (
`id` int(11) NOT NULL DEFAULT '0',
`dDate` date DEFAULT NULL,
`type` varchar(100) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 |
+---------------+---------------------------------------------------------------
--------------------------------------------------------------------------------
-------------------------+
1 row in set (0.00 sec)

非常感谢您的帮助..

最佳答案

我改变了:

LEFT JOIN ". TABLE_EMAIL ." AS email ON contact.id=email.id AND contact.primaryAddType=email.type

到:

LEFT JOIN ". TABLE_EMAIL ." AS email ON contact.id=email.id

我想在使用两个 LEFT JOIN 时永远不会有两个 primaryAddType

所以现在一切正常了!!!!感谢大家!! :)

关于mysql - 我无法使用 ORDER BY(日期类型),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13633502/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com