简单的order by子句不使用内连接

时间:2011-07-26 00:16:03

标签: php mysql

这个查询根本就没有按照我想要的方式对结果进行排序:

$sql = mysql_query("select s.*, p.label, p.number
                    from `sales` as s 
                    left join `pumps` as p on (p.id = s.id_pump)
                    where s.the_date >= UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 1 DAY))
                    order by CAST(s.amount_sale AS int) desc
                    limit 1") or die(mysql_error());

我收到了一个mysql错误。

1 个答案:

答案 0 :(得分:2)

尝试将VARCHAR转换为有符号整数:

$sql = mysql_query("select s.*, p.label, p.number
                    from `sales` as s 
                    left join `pumps` as p on (p.id = s.id_pump)
                    where s.the_date >= UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 1 DAY))
                    order by CAST(s.amount_sale AS SIGNED) desc
                    limit 1");