gpt4 book ai didi

MySQL order by ... 奇怪的顺序

转载 作者:行者123 更新时间:2023-11-29 04:27:52 24 4
gpt4 key购买 nike

我在 mysql 请求中遇到了一个 order by 的小问题。

这是我的要求:

SELECT p.*, 
pa.`id_product_attribute`,
pl.`description`,
pl.`description_short`,
pl.`available_now`,
pl.`available_later`,
pl.`link_rewrite`,
pl.`meta_description`,
pl.`meta_keywords`,
pl.`meta_title`,
pl.`name`,
i.`id_image`,
il.`legend`,
m.`name` AS manufacturer_name,
tl.`name` AS tax_name,
t.`rate`,
cl.`name` AS category_default,
DATEDIFF(
p.`date_add`,
DATE_SUB(NOW(),
INTERVAL 0 DAY
)) > 0 AS new,
(p.`price` * IF(t.`rate`,((100 + (t.`rate`))/100),1)) AS orderprice
FROM `ps_category_product` cp
LEFT JOIN `ps_product` p ON p.`id_product` = cp.`id_product`
LEFT JOIN `ps_product_attribute` pa ON (p.`id_product` = pa.`id_product` AND default_on = 1)
LEFT JOIN `ps_category_lang` cl ON (p.`id_category_default` = cl.`id_category` AND cl.`id_lang` = 2)
LEFT JOIN `ps_product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = 2)
LEFT JOIN `ps_image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1)
LEFT JOIN `ps_image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = 2)
LEFT JOIN `ps_tax_rule` tr ON (p.`id_tax_rules_group` = tr.`id_tax_rules_group` AND tr.`id_country` = 8 AND tr.`id_state` = 0)
LEFT JOIN `ps_tax` t ON (t.`id_tax` = tr.`id_tax`) LEFT JOIN `ps_tax_lang` tl ON (t.`id_tax` = tl.`id_tax` AND tl.`id_lang` = 2)
LEFT JOIN `ps_manufacturer` m ON m.`id_manufacturer` = p.`id_manufacturer`
WHERE cp.`id_category` = 4005 AND p.`active` = 1 ORDER BY p.`location` ASC

我的结果是这样的:

1,10,11,12,13,14,2,3,4,5,6,7,8,9 ...

在我的表中,location 被定义为 un varchar (64)。我想这是问题所在……但是,我需要这个字段 varchar……我需要(有时)将这个字段排序为 int 值。

这可能吗?

感谢阅读

最佳答案

试试这个:

ORDER BY CAST(p.location AS SIGNED) ASC

关于MySQL order by ... 奇怪的顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8051815/

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