如果查询中包含的mysql中的别名排序 [英] Order by alias in mysql contained in if query

查看:396
本文介绍了如果查询中包含的mysql中的别名排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用查询从不带美元的价格列中选择价格,然后在if语句后按该别名排序。但是按该别名命名的命令不起作用。

I am using a query to select price from price column without dollar and then order by that alias after if statement. But order by that alias name is not working.

我正在使用的查询是

SELECT 
  *, 
  IF( SUBSTRING( price , '1', '1' ) = '$', 
      round( replace( price , '$', '' ) ) ,
      price ) AS coupon 
FROM ccs_product 
WHERE (product_name LIKE '%JoyLot.com%' 
       OR website_name LIKE '%JoyLot.com%' 
       OR description LIKE '%JoyLot.com%')
ORDER BY coupon ASC 
LIMIT 0 , 10;


推荐答案

使用此查询,其作品使用round(price)

use this query its works use round(price)

   SELECT 
       *, 
         IF( SUBSTRING( price , '1', '1' ) = '$', 
              round( replace( price , '$', '' ) ) ,
              round(price) ) AS coupon 
          FROM ccs_product 
         WHERE (product_name LIKE '%JoyLot.com%' 
     OR website_name LIKE '%JoyLot.com%' 
     OR description LIKE '%JoyLot.com%')
        ORDER BY coupon ASC 
   LIMIT 0 , 10;

这篇关于如果查询中包含的mysql中的别名排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆