会员表结构
==========================
会员id
会员标记 (1正式 0免费)
注册时间
消费总额
==========================模拟数据
-----------------------------
id,标记,时间,消费
1 1 2008-4-1 1000
2 1 2008-4-5 800
3 0 2004-5-5 0
4 1 2008-4-23 4000
5 0 2008-4-25 0----------------------------最后需要的结果排序如下:
id 标记 时间 , 消费
4 - 4000 (消费多的排前头)
1 - 1000
2 - 800
5 2008-4-23 0 (后注册往前排)
3 2004-5-5 0
==========================
会员id
会员标记 (1正式 0免费)
注册时间
消费总额
==========================模拟数据
-----------------------------
id,标记,时间,消费
1 1 2008-4-1 1000
2 1 2008-4-5 800
3 0 2004-5-5 0
4 1 2008-4-23 4000
5 0 2008-4-25 0----------------------------最后需要的结果排序如下:
id 标记 时间 , 消费
4 - 4000 (消费多的排前头)
1 - 1000
2 - 800
5 2008-4-23 0 (后注册往前排)
3 2004-5-5 0
Select tab.id,标记,时间,t1.消费总额
From tab Left Join
(Select id,Sum(消费) As 消费总额
From tab Group By id) t1 On tab.id=t1.id
Order By t1.消费总额 DESC,日期 DESC
select * from tb order by (case when 标记 = 1 then 消费 else 0 end) desc,时间 desc