我有一个表transaction(id, quantity, rate, stock_code, user_code)
,我希望根据它们的数量按降序生成前三个交易。 Amount = quantity * rate
有没有办法只使用sql生成?
答案 0 :(得分:2)
是的,有可能:
SELECT id, quantity * rate as amount, stock_code, user_code
FROM transaction
ORDER BY 2 DESC
LIMIT 3;