我正在使用以下查询根据其定义的等级
对行进行排序select
properties.id,
properties.agency_id,
properties.created,
IF(@prev <> properties.agency_id, @cnt := 1, @cnt := @cnt + 1) AS rank,
@prev := properties.agency_id,
properties.refno
FROM properties
INNER JOIN agency ON properties.agency_id = agency.agency_id
order by agency.priority, rank , properties.created desc
我想根据'created'和agency_id对最新行进行排名。我怎么能实现它????任何帮助将不胜感激。
properties table
id agency_id created refno sell_price
1 1001 2013-12-10 A1-1001 1000000
2 1002 2013-12-09 A2-1002 5000000
3 1001 2013-12-20 A3-1001 9000000
4 1001 2013-12-21 A4-1001 7000000
5 1002 2013-12-25 A5-1002 6500000
6 1003 2013-12-26 A6-1003 5600000
(http://sqlfiddle.com/#!9/84c0b/1/0)
现在我想在创建的列上对它们进行排序,并根据agency_id对它们进行排名。然后想根据agency.priority对它进行排序。我已在代理商表中定义了优先级。如下
id agency_id created refno sell_price
1001 2013-12-21
1002 2013-12-25
1003 2013-12-26
1001 2013-12-20
1002 2013-12-09
1001 2013-12-10