Skip to main content

SQL Journey: Blog #3

I have reached the end of lesson 2. The final project is entitled "Data dig" where we are given a set of interesting 

data sets: NASA astronauts, Superbowl results, Pokemon stats, NBA players, Top movies, Top countries by population, Solar system objects by size, Marvel characters, Furniture store sales, Earned KA badges, Winston's donut logs, Card game results, and NFL draft picks.

We are to pick one of those data sets and use advanced SELECT queries to discover things about the data. What sort of questions might one have about that data, like if they were using it for an app or a business idea? Here are some ideas:What are average, max, and min values in the data?
What about those numbers per category in the data (using HAVING)?
What ways are there to group the data values that don’t exist yet (using CASE)?
What interesting ways are there to filter the data (using AND/OR)?

Basically, the above given questions will serve as a guide on what we could dig from the given data set. Since these are generic questions that will serve as guide, we will deal with it later. For now, let us select what data set we shall use. I chose Top movies. Given below is the database schema.

topmovies100 rows
RankINTEGER
TitleTEXT
StudioTEXT
WorldwideREAL
DomesticREAL
DomesticPctREAL
OverseasREAL
OverseasPctREAL
YearINTEGER
If I have this dataset, the first question I could possibly ask is, "How much is the maximum and minimum worldwide box office earnings for movies that belong to the top 100?" Here, we could use the following code to get the value:

SELECT title, MAX(Worldwide) FROM topmovies;
SELECT title, MIN(Worldwide) FROM topmovies;

QUERY RESULTS

TitleMax(Worldwide)
Avatar2788
TitleMIN(Worldwide)
Tangled591.8

The next question I could possibly ask is, "How much is the average worldwide, average domestic, and average overseas gross revenue for the top 100 movies?" Here, we could use the following code to get the value:

SELECT title, ROUND(AVG(Worldwide)) AS avg_worldwide, ROUND(AVG(Domestic)) AS avg_domestic, ROUND(AVG(Overseas)) AS avg_overseas FROM topmovies;

By doing this, up and coming movies will be able to assess whether they are below, equal, or above the worldwide, domestic, and overseas average gross revenues. 

QUERY RESULTS

avg_worldwideavg_domesticavg_overseas
863307555
For example, for the movie, "The Greatest Showman" which I liked watching, its worldwide box office is $430.58 million, domestic box office is $174.34 million, and overseas box office is $256.24 million. All these values are below the calculated averages.

Another thing, I could ask is, "How many movies were included in the top 100 movies when grouped by studio? Which among the studios have the highest number of count and the lowest number of count?" Here, we could use the following code to get the value:

SELECT Studio, COUNT(*) FROM topmovies GROUP BY Studio ORDER BY COUNT(*);

SELECT Studio, COUNT(*) FROM topmovies GROUP BY Studio HAVING COUNT(*) = 23;

SELECT Studio, COUNT(*) FROM topmovies GROUP BY Studio HAVING COUNT(*) = 1;

QUERY RESULTS


StudioCOUNT(*)
DW1
LG/S1
NM1
LGF3
NL3
Sum.3
Par.7
Uni.8
P/DW9
Sony11
Fox13
WB17
BV23
StudioCOUNT(*)
BV23
StudioCOUNT(*)
DW1
LG/S1
NM1

Another question would be, "How much is the average worldwide box office revenue when grouped by studio?" Here, we could use the following code to get the value:

SELECT Studio, ROUND(AVG(Worldwide)) AS avg_worldwide FROM topmovies GROUP BY Studio ORDER BY avg_worldwide;

QUERY RESULTS

Studioavg_worldwide
NM612
Sum.707
P/DW763
Sony768
LGF769
LG/S830
Uni.845
BV871
DW920
WB923
Fox924
Par.962
NL972

Comments

Popular posts from this blog

Privacy Policy of ShinStats: descriptives calc

Privacy Policy Shin Nix built the ShinStats app as an Ad Supported app. This SERVICE is provided by Shin Nix at no cost and is intended for use as is. This page is used to inform visitors regarding my policies with the collection, use, and disclosure of Personal Information if anyone decided to use my Service. If you choose to use my Service, then you agree to the collection and use of information in relation to this policy. The Personal Information that I collect is used for providing and improving the Service. I will not use or share your information with anyone except as described in this Privacy Policy. The terms used in this Privacy Policy have the same meanings as in our Terms and Conditions, which are accessible at ShinStats unless otherwise defined in this Privacy Policy. Information Collection and Use For a better experience, while using our Service, I may require you to provide us with certain personally identifiable information. The information that I request will be retaine...

Power BI Journey: Blog #6

In this lesson, the focus is on "Conditional Formatting" which is very much similar to the conditional formatting in MS Excel which I could relate to following the making of the joint reporting system for personnel during my second job. Basically, we click the data columns that we want to be displayed in a tabular visualization.  Next, we select the columns that we will be applying conditional formatting to > Right-click on that column > Select Conditional Formatting > Select from among the options which is more appropriate for your application In this particular exercise, we utilized Background conditional formatting using gradient (applied on the first column of the first table) and rules (IF ELSE which was applied on the second column of the first table), Icons conditional formatting (applied on the second column of the first table), Data bars conditional formatting (applied on the second column of the first table and the fourth column of the second table). In the...