1) Select fields instead of using SELECT *. The “*” is used as a short hand to query all available data from a table. If a table has many fields and rows, this takes database resources by querying a lot of unnecessary data. … Read more ›...
1) Select fields instead of using SELECT *. The “*” is used as a short hand to query all available data from a table. If a table has many fields and rows, this takes database resources by querying a lot of unnecessary data. … Read more ›...
In SQL often we need to merge records from a source table to a target table. The source table could be a staging table where the source system sent new & updated records to be reconciled with the a target table. Let’s look at an example as to how to...
Q1. What is an XML? A1. XML stands for eXtensible Markup Language. XML is a grammatical system for constructing custom markup languages for describing business data, mathematical data, chemical data etc. XML loosely couples disparate applications or systems utilizing JMS, … Read more ›...
Let’s look at a standard teams interview question to understand your SQL knowledge in using a non-equi join. Problem Statement 1 Given the below 5 teams
|
1 2 3 4 5 6 7 8 9 |
team_id team_name ------------------------ 1 Team A 2 Team B 3 Team C 4 Team D 5 Team E |
1) Write a query so that each team plays with each other only once. 2) Write a query so that each team plays...
Q01. What is Amazon S3 storage? A01. S3 stands for Simple Storage Service, which provides storage through web service interfaces. Unlike the other storage systems like Unix file system, HDFS (i.e. Hadoop Distributed File System), etc which are based on having folders and files, the S3 is based on a...
Here is another SQL scenario based interview question to determine a candidate’s ability to translate a business requirement into an SQL query. Problem Statement Given the below data of running account balance, find the start_date and end_date where the balance changes.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
id balance date ------------------------------------- 1 24000.00 2023-01-15 2 24000.00 2023-01-16 3 19000.00 2023-01-17 4 19000.00 2023-01-18 5 22000.00 2023-01-19 6 24000.00 2023-01-20 7 24000.00 2023-01-21 8 29000.00 2023-01-22 9 29000.00 2023-01-23 10 29000.00 2023-01-24 |
Expected output:
|
1 2 3 4 5 6 7 8 9 |
balance start_date end_date ---------------------------------------------- 24000.00 2023-01-15 2023-01-16 19000.00 2023-01-17 2023-01-18 22000.00 2023-01-19 2023-01-19 24000.00 2023-01-20 2023-01-21 29000.00 2023-01-22 2023-01-24 |
Create sample data
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
CREATE TABLE IF NOT EXISTS account_balance (id INT, balance DECIMAL(10,2), date DATE ); INSERT INTO account_balance(id, balance, date) VALUES (1, 24000.00, '2023-01-15'); INSERT INTO account_balance(id, balance, date) VALUES (2, 24000.00, '2023-01-16'); INSERT INTO account_balance(id, balance, date) VALUES (3, 19000.00, '2023-01-17'); INSERT INTO account_balance(id, balance, date) VALUES (4, 19000.00, '2023-01-18'); INSERT INTO account_balance(id, balance, date) VALUES (5, 22000.00, '2023-01-19'); INSERT INTO account_balance(id, balance, date) VALUES (6, 24000.00, '2023-01-20'); INSERT INTO account_balance(id, balance, date) VALUES (7, 24000.00, '2023-01-21'); INSERT INTO account_balance(id, balance, date) VALUES (8, 29000.00, '2023-01-22'); INSERT INTO account_balance(id, balance, date) VALUES (9, 29000.00, '2023-01-23'); INSERT INTO account_balance(id, balance, date) VALUES (10, 29000.00, '2023-01-24'); |
Solution...
Here is another SQL scenario based interview question to determine a candidate’s ability to translate a business requirement into an SQL query. These are scenarios where you want to find a value at a certain point in time. Lean more about SCD Type 2 at 13 Data Warehouse interview Q&As...
Method Vs. Closure Q1. What are the differences between a method and a closure? A1. Both methods and closures add behavior, and they basically have a block of code containing expressions and statements within two curly brackets i.e. {…} . … Read more ›...
Let’s look at a very common problem statement of finding out the repeat customers, repeat visits, etc. The key to this problem is first determining the first visit or first purchase and then comparing it with the remaining records. Problem Statement 1 Given the below table, how will you determine...
This extends Finding your way around FIX specification Q&A. Q1. What product classes does FIX protocol support? A1. Equities, Equity Derivatives (e.g. Options, Warrants, Futures, ETFs, Swaps, etc), Fixed Income, FX (aka Forex), FX derivatives, etc. Q2. What are the key message categories? … Read more ›...
We all know how to get a distinct count of a column. It can be done with COUNT(DISTINCT column_name). For example:
|
1 2 3 4 |
SELECT COUNT(DISTINCT user_id) FROM web_store |
Outputs:
|
1 2 3 4 5 |
COUNT(DISTINCT user_id) ------------------------- 6 |
In this post let’s look at various approaches to count unique values. Using DISTINCT, … Read more ›...
This extends Common Table Expressions (i.e. CTE) in SQL using the “WITH” clause. You can try the example on DB Fiddle. Use MySQL v8.0 or later. Scenario: 1 Given a table like this with each entry with two dates (i.e. from_date & … Read more ›...
One of the common SQL interview questions is to quiz your understanding of SQL joins. In this let’s look at joins example with two scenarios.
Venn Diagram
Joins can be specified as a venn diagram shown below:
But, it gets a bit more tricky when you consider the below scenarios:
Scenario 1: When both input tables don’t have duplicate values.
…
I have a good news, I got job offer. I like to share with you from my bottom of my heart feeling thankful to you.