1
davansy 2014-04-21 13:13:37 +08:00
尽量不要在数据库中做复杂的操作。楼主的需求可以通过另起一张表单独记录中奖率的信息
|
2
skydiver 2014-04-21 13:20:45 +08:00
根据两个表建立一个view,然后在view里排序
|
3
twoconk 2014-04-21 13:24:03 +08:00 via Android
单独起一张表合适
|
4
pythoner 2014-04-21 13:27:12 +08:00
把中奖率算出来放到其它地方排序
|
5
123123 2014-04-21 14:41:32 +08:00
建个view +1
|
6
crazybubble 2014-04-21 14:52:52 +08:00
SELECT sales_sum.user, sales_sum.deals, jackpot_sum.jackpots
FROM (SELECT sales.user, count(sales.product_id) AS deals FROM sales GROUP BY sales.user) AS sales_sum, (SELECT jackpot.user, count(jackpot.id) AS jackpots FROM jackpot GROUP BY jackpot.user) AS jackpot_sum WHERE sales_sum.user = jackpot_sum.user ORDER BY (jackpot_sum.jackpots / sales_sum.deals) DESC; |