0

所以,简短解释:我想从表 games_records 中获取所有记录,按最高 furni 值 (pricelist_furnis_tradevalue.value) 乘以记录数量 (= games_records.amount) 排序。furni 值在 pricelist_furnis_tradevalue 中。现在... pricelist_furnis_tradevalue 有一些家具的多个条目。我只想获得最新的条目,因此它应该按 pricelist_furnis_tradevalue.time 排序。但是下面的这个查询返回 pricelist_furnis_tradevalue 中每个 furni/record 的所有条目。

SELECT *
FROM games_records 
JOIN pricelist_furnis_tradevalue 
    ON games_records.furni = pricelist_furnis_tradevalue.furni
ORDER BY (pricelist_furnis_tradevalue.value*games_records.amount) DESC

这是2个所需表的结构

游戏记录

id      user        furni       amount      time
1       2           4           40          1338052926
2       4           30          90          1338054046

pricelist_furnis_tradevalue

id      furni       value       time
1       2           20          1334065379
2       2           50          1334067445
3       2           100         1334092057
4       4           50          1334065375
4       4           20          1334067436

我会很感激任何帮助!谢谢!

4

2 回答 2

0
SELECT * FROM 
    (SELECT *, pricelist_furnis_tradevalue.value*games_records.amount AS 'mult' FROM games_records 
    JOIN pricelist_furnis_tradevalue 
    ON games_records.furni = pricelist_furnis_tradevalue.furni) a
ORDER BY a.mult DESC
于 2012-07-18T19:55:19.607 回答
0

您需要获取最长时间的记录。

这是一种方法:

SELECT *
FROM games_records join
     (select furni, max(time) as maxtime
      from pricelist_furnis_tradevalue
      group by furni
     ) as maxf
     on games_records.furni = maxf.furni JOIN
     pricelist_furnis_tradevalue 
     ON games_records.furni = pricelist_furnis_tradevalue.furni and
        pricelist_furnis_tradevalue.time = maxf.maxtime
ORDER BY (pricelist_furnis_tradevalue.value*games_records.amount) DESC
于 2012-07-18T19:56:25.090 回答