Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

narwen's avatar

Generate top three maximum transaction from the db

I have a transaction(id, quantity, rate, stock_code, user_code) table and I want to generate the top three transactions on the basis of their amount in descending order. Amount = quantity * rate

Is there a way to generate using only sql ?

0 likes
2 replies
postitief's avatar
Level 5
DB::select('SELECT quantity * rate AS amount FROM transaction ORDER BY amount DESC LIMIT 3');
1 like

Please or to participate in this conversation.