SQL Query Display the trade id stock i and total price for the secondary market
ID: 3909118 • Letter: S
Question
SQL Query
Display the trade id stock i and total price for the secondary market trade with the highest total price. Convert prices to U.S dollars
select tr.trade_id, tr.stock_id, round(tr.price_total * con.exchange_rate,2) as "US Dollars"
from stock_exchange se
join trade tr
on se.STOCK_EX_ID = tr.STOCK_EX_ID
join currency curr
on curr.CURRENCY_ID = se.currency_id
join conversion con
on con.from_CURRENCY_ID = curr.CURRENCY_ID
Where (tr.PRICE_TOTAL) = (Select Max(price_total) from trade) and curr.name = 'Dollar'
group by tr.trade_id, tr.stock_id, round(tr.price_total);
tried but i keep getting errors about it not being a group by function
Explanation / Answer
If you still getting any error / have any doubts, please give me comment...
SELECT tr.trade_id, tr.stock_id, ROUND(tr.price_total * con.exchange_rate,2) as 'US Dollars'
FROM stock_exchange se JOIN trade tr ON se.STOCK_EX_ID = tr.STOCK_EX_ID JOIN currency curr ON curr.CURRENCY_ID = se.currency_id JOIN conversion con
ON con.from_CURRENCY_ID = curr.CURRENCY_ID
WHERE (tr.PRICE_TOTAL) = (
SELECT Max(price_total) FROM trade
) and curr.name = 'Dollar'
GROUP BY tr.trade_id, tr.stock_id;
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.