Sales Analysis – 3

Tables – product and sales are provided. Write SQL query to identify products which were sold only in first quarter of year 2019. If a product is sold in any other quarter then that is not supposed to be present in final output. Output should be product_id and product_name. Input Table: sales seller_id product_id buyer_id … Read more

SQL Contest – 14 days hackathon

Started on 1st July, 2019 – 2 weeks long hackathon was conducted, which concluded on 14th July, 2019. Data was collected for each participant and you are expected to write a query to print four columns as below : Contest Date Total number of unique participants who made at least 1 submission every day ( … Read more

Post Views – 2

Post views are being analysed using post_views table. This table contains information of all views on each posts date wise.Task is to find all viewers (viewer_id) who viewed more than one post on same date. Sort the final output in ascending order.   Input Table: post_views post_id author_id viewer_id view_date 22 2 4 2017-01-10 44 … Read more

Post Views – 1

Post views are being analysed using post_views table. This table contains information of all views on each posts date wise.Task is to find all authors who viewed at least one of their own posts. Sort the final output by their author_id in ascending order.   Input Table: post_views post_id author_id viewer_id view_date 22 2 4 … Read more

Product Sales Analysis – 3

Write a SQL query that selects the product id, sale year, quantity, and price for the first year of every product sold.   Input Table : sales sale_id product_id sale_year quantity price 20 80 2017 21 300 30 80 2018 23 400 40 13 2019 56 600   Output Table: product_id first_year quantity price 80 2017 21 300 13 … Read more

Product with sales increasing every year

A multinational Company is going through very bad timings and now want to focus on products which has shown increased sales and profit every year. They are looking for your help in identifying such products so that they can plan marketing campaign accordingly. Input Table – Product_sales sale_year product_id units_sold 2016 1 1000 2016 2 … Read more

Product Sales Analysis – 2

Write an SQL query that reports the total quantity sold for every product id.   Input Table : sales sale_id product_id sale_year quantity price 20 80 2017 21 300 30 80 2018 23 400 40 13 2019 56 600   Output Table: product_id total_quantity 80 44 13 56   Explanation: product_id is Foreign Key and … Read more

Product Sales Analysis – 1

Write an SQL query that reports all product names of products in the “sales” table along with their selling year and price.   Input Table : sales sale_id product_id sale_year quantity price 20 80 2017 21 300 30 80 2018 23 400 40 13 2019 56 600   Input Table: product product_id product_name 80 Asus … Read more

Shortest distance in line on x-axis

Points of x coordinates are stored in table “points“. All entries of these points in table are integers and unique. Write a query to find shortest distance between two points on x-axis.   Input Table: points x-axis -3 -6 0 10 Output Table: shortest 3 Explanation: All possible combinations of all points in input table … Read more