Tbone Profile picture
Jun 6 10 tweets 5 min read Twitter logo Read on Twitter
Let's break down each code
1. The ending part to the question is where the major conditional logic lies. We were told to return the needed columns, and price for the first year of every product sold. Since we do not have distinct column showing min years for each product,
We have to create that with a subquery in the Where clause. We are concerned about the first year of every product sold, so we aggregate the min years for each product. After doing that, we tell SQL to return the prices of products, the year, and qty when the product was first..
Sold(i.e first year).
2. This is pretty straight forward. We applied the modulus operandi for the IDs, to return movies with an odd number. Hence the need for this-(id%2 <> 0). We also want those movies that aren't boring, hence the not equals to operator was used
3. This was a bit tricky. This was due to this part of the conditions we were given (SQL will always make you read btw the lines). Wahala.. Dem wan use English finish me Image
Just look at this part - "Each row of the prices indicate the product_id price. For each product_id,there'll be no two overlapping periods".
To put it in lame man terms. What they want from us is to ensure that we show that for each product sold oo, the time(purchase_date)..
.. it was purchased must fall in between the start date and End date that of when each unique prices were set for those products. *I just hope I'm not overcomplicating things for you rn*
To make it make further sense ehn. Coca-cola bottling company changed their prices for coke a few times. In Jan, it was $3. In Feb it was $2.5. Hence the Filtering clause we included. If we don't do this, we will be giving the prices for a product at a time to another period.
Every other part of the query just helps us to aggregate the avg prices for each product sold. Make sense, eh?
Kindly let me know your thoughts. Thank you for staying with me. Merci beaucoup 💛
#SQL #DataAnalytics #Jobs

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Tbone

Tbone Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @Toby_Davids

Jun 8
#Day5 for Reporting "Crack SQL interview in 50Qs" is hear. Let's rumble

Find the links to the questions here
1. leetcode.com/problems/the-n…
2. leetcode.com/problems/prima…

#SQL #DATAANALYSIS #Interviews #lowcode Image
Let's break them down:
1. Intuition
The query aims to retrieve information about managers in the Employees table, including their IDs, names, the number of employees reporting to them, and the average age of their reports.
The solution involves using a self join. Since we were told that a manager is also an employee, we will join the table to itself, where the employee_id field is equal reports_to field. On this premise, we aggregate the number of employees who report directly to the manager,
Read 6 tweets
Jun 8
A few days back, 2 Data Analyst newbies showed me mistakes they encountered during their analysis process. It dawned on me that lots of times, we don't diligently follow through the data analysis process, especially the cleaning phase.
In this short🧵, I break down this process. Image
PHASE 1: ASK QUESTIONS
The first step in the analysis process is to formulate a problem to solve or a question to answer, such as: are customers aged 21 to 30 more likely to churn than customers aged 41 to 50? As analysts, we must be very curious, we must ASK QUESTIONS!
PHASE 2: Collect & Store Data
Next, we need to collect and store the necessary data, which could require the use of a database or a spreadsheet. For large datasets, we store them in a database. For datasets shy of a million records, spreadsheet software like Excel can be used.
Read 12 tweets
Jun 8
Let's break down each question
1. Logic: Show the classes, where the number of student is more than 5. The word "At least" tells us something, we have to include 5 as part of our filtering condition, hence >=5
2. This looks pretty straight forward. For each user, we want to....
..return the number followers, hence the need to use the Group BY clause. This clause allows us to aggregate data against the unique categorical/qualitative values in a field.
3. The given SQL query finds the maximum value (num) from the "mynumbers" table that appears only once.
Read 9 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us on Twitter!

:(