0

我不是 SQL 专家,因此需要您的帮助。

我有这个由其他人编写的高级查询:

SELECT cms_product_bid.*,
    cms_products.*,
    cms_products_images.pd_image, 
    cms_products_images.pd_image_label,
    IF (cms_product_bid.pd_bid = 1,
        IF(cms_product_bid.pd_bid_start_date <= CURDATE(),
            IF(cms_product_bid.pd_bid_end_date >= CURDATE(),1,0)
        ,0)
    ,1)  AS bid_product_check
FROM cms_products
LEFT JOIN cms_products_images 
ON (cms_products.pd_id = cms_products_images.pd_id)
INNER JOIN cms_product_bid 
ON (cms_product_bid.product_id = cms_products.pd_id)
INNER JOIN cms_home_product_slider 
ON (cms_products.pd_id = cms_home_product_slider.pd_id)
WHERE cms_products.pd_status=1 
    AND cms_products.pd_visibility=1 
    AND cms_home_product_slider.cat_id='$featured_cat_id'
GROUP BY cms_products.pd_id 
HAVING(bid_product_check =1)
ORDER BY cms_products.pd_sort ASC

我要做的只是排序,cms_products.pd_sort但它不是按该列排序,即使表中的列具有诸如 等的12

谁能在这里指出这个问题?

4

2 回答 2

2

我的猜测是您的列是类型VARCHAR字符串,您可以简单CAST

SELECT...
FROM...
WHERE...
ORDER BY CAST(cms_products.pd_sort AS SIGNED) ASC
于 2013-01-07T13:54:56.677 回答
1

这可能是一个错误...但尝试列出列而不是使用 .* 快捷方式...然后查看该列是否会被正确识别和排序。

顺便说一句 - 由于许多原因,使用 .* 并不是最佳实践。

于 2013-01-07T13:55:39.110 回答