Header Ads Widget

Profitable Stocks | Hackerrank certification solution

 Profitable Stocks | Hackerrank certification solution

A stock is considered profitable if the predicted price is strictly greater than the current price. Write a query to find the stock_codes of all the stocks which are profitable based on this definition. Sort the output in ascending order.

 Profitable Stocks | Hackerrank certification solution

 the objective of code is to print the stock_code which is profitable . for specification see the sample input and output .

There are two tables in the database: price today and price tomorrow. Their primary keys are stock code.


Sample output:-



  • For TITAN, today's stock price is 560 and its predicted price is 750, hence it is a profitable stock
  • For MRF, today's stock price is 950 and its predicted price is 800, hence it is not a profitable stock
  • For GOOGL, today's stock price is 200 and its predicted price is 210, hence it is a profitable stock

Mysql code:-

select p.stock_code from price_today p inner join price_tomorrow pp on
p.stock_code=pp.stock_code where p.price<pp.price order by p.stock_code

Recommended Post :-

HCL Coding Questions:-

Capgemini Coding Questions:-

Companies interview:-

Full C course:-    

Key points:-

Cracking the coding interview:-

 Array and string:-

Tree and graph:-

Hackerearth Problems:-

Hackerrank Problems:-

Data structure:-


Post a Comment