5. SQL Interview Queries | sql interview questions and answers | #50DaySQLQueryChallenge

preview_player
Показать описание
#50DaySQLQueryChallenge
50DaySQLQueryChallenge is a series of 50 videos covering 50 SQL Interview Queries. This is the third video in this series. This video series aims to provide 50 SQL Queries that can be asked during SQL Interviews. In these videos, I will explain how to solve and address such SQL queries during interviews.
This particular video covers an SQL Interview query.

SQL Script:
Please check comment box

CREATE TABLE part5sqlquiz
(
CustId Int,
CustName varchar(250),
SaleDt Date,
amount int
)

Insert Into part5sqlquiz
Values (1,'Jhon','2024-04-01',100), (2,'Daniel','2024-04-02',110), (3,'Jade','2024-04-03',120), (4,'Khaled','2024-04-04',130), (5,'Winston','2024-04-05',110),
(6,'Elvis','2024-04-06',140), (7,'Anna','2024-04-07',150), (8,'Maria','2024-04-08',80), (9,'Jaze','2024-04-09',110), (1,'Jhon','2024-04-10',130)
, (3,'Jade','2024-04-10',150)

Let's follow the below playlist to make the best use of it:
1. SQL Quiz 50 days challenge:

2. sql server complex interview questions and answers:

3. SQL server real-time scenario:

4. SQL Server interview questions and answers:
Рекомендации по теме
Комментарии
Автор

;with cte as
(
Select *, CASE WHEN day(saledt)<=7 Then '1'
WHEN day(saledt)<=14 Then '2'
WHEN day(saledt)<=21 Then '3'
WHEN day(saledt)<=28 Then '4'
ELSE '5' END AS weeknum
From part5sqlquiz
)
SELECT max(saledt) as saledt, sum(amount) as totalamount, avg(amount) as avg_amount
from cte
group by weeknum

ssunitech
Автор

select
max(SaleDt) as saldate, sum(amount) as totalAmt, AVG(amount) as AvgAmt
from part5sqlquiz
group by
(case when day(SaleDt)<=7 then 1
when day(SaleDt)<=14 then 2
when day(SaleDt)<=21 then 3
when day(SaleDt)<=28 then 4 else 5 end )

LalanKumarSahu-nw
Автор

in my SQL

;with cte as
(
select *
, case when DATEPART(d, SaleDt) <= 7 then 1
when DATEPART(d, SaleDt) <= 14 then 2
when DATEPART(d, SaleDt) <= 21 then 3
else 4
end as WeekNum
from part5sqlquiz
)

select MAX(SaleDt) as SaleDt, SUM(amount) as Total_Amount, AVG(amount) as AVG
from cte
Group by Weeknum

CebuProvince
Автор

select
max(SaleDt) as saldate, sum(amount) as totalAmt, AVG(amount) as AvgAmt
from part5sqlquiz
group by
(case when day(SaleDt)<=7 then 1
when day(SaleDt)<=14 then 2
when day(SaleDt)<=21 then 3
when day(SaleDt)<=28 then 4 else 5 end )

LalanKumarSahu-nw