【问题标题】:ordering results in MySQL [closed]MySQL中的排序结果[关闭]
【发布时间】:2013-07-22 13:31:31
【问题描述】:

我在使用 SQL ORDER 函数时遇到问题。我的产品数据库有图片和价格。我想要的是像这样订购我的结果:所有产品的图片显示价格从低到高,然后我的产品没有图片显示价格从低到高。

任何帮助将不胜感激。

更新: 这是我的表结构:

id - brand - code - name - type - pile_weight - size - pcs_ctn - sf_ctn - lbs_ctn - picture - description - color_code - manufacturer - supplier - pricing_unit - total_wgt - retail_price - sale_price - dealer_price - featured

就查询而言,这是我所做的:

SELECT * FROM products ORDER BY picture, retail_price
SELECT * FROM products ORDER BY picture DESC, retail_price ASC
SELECT * FROM products ORDER BY CASE WHEN picture = '' THEN 1 ELSE 0 END, picture, retail_price ASC

【问题讨论】:

  • 请添加您当前的查询,并证明您已尝试解决问题。
  • 要获得答案,您至少应该描述您的表格结构
  • 尝试添加ORDER BY img_column, price_column where img_column
  • order by img = '' desc, price asc

标签: php mysql sql database


【解决方案1】:

您应该清楚地提及您的餐桌设计。我仍然在这个 sqlfiddle 发布你的解决方案 http://sqlfiddle.com/#!2/eb8f7/2

select * from table1 order by ifnull(image,0) ,price asc

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-10-27
    • 1970-01-01
    • 1970-01-01
    • 2013-01-03
    • 1970-01-01
    • 1970-01-01
    • 2018-03-14
    • 2013-12-18
    相关资源
    最近更新 更多