Posts

Showing posts from June, 2022

SQL Bars?

Image
While browsing through some SQL puzzles, I came across one where it asked to create a bar chart inside SQL server. Initial thought - It will require some sort of text manipulation. But before that I need to structure the data in proper format. Input Table:- The problem is divided into 3 parts:- Get regions and their total quantities. Because total quantities would be huge, it will not be possible to plot them as bars. Therefore, convert those quantities into percentage of total value. Create bars for percentage of total value against each region. SQL script with cte as ( select Region, sum(Order_Quantity) as Quantity, sum(SUM(Order_Quantity)) over () as [Total Quantity], round( ( CAST( sum(Order_Quantity) as float ) / cast (sum(sum(Order_Quantity)) over () as float ) ) * 100 ,0) as [% Total] from superstore group by Region ) select Region, [% Total], REPLICATE('|',[% Total]) as [Bars] from cte Output Table:- It was a fun little exercise to think outside the box and how you ca...

Movie-Lookup

Image
Ever wonder which movie should I watch this weekend?  You login to your favorite streaming service just to find yourself struck in vicious loop of  checking it's rating on IMDB and then searching for some more before deciding on that one movie which you might find interesting. I thought wouldn't it be great to have a dashboard with movies rated and you can apply some criteria to find what movie you are looking for. I searched for IMDB data and found it on kaggle website. This data is used to create and train recommendation systems, but for me a simple dashboard was enough to find movies I might enjoy on my weekend.