No video

Tricky SQL Screening Question | Applicants Failing to Get the Query Correct

  Рет қаралды 1,649

Absent Data

Absent Data

Күн бұрын

This is a real SQL interview screening question for a medium size marketing firm that was trying get a specific answer from interviewees. I provide 3 ways to answer the pretty easy question. The tricky part would be not using a join to answer the question. This was also posted on Reddit and got some interesting feedback
0:20 Reddit Post
0:38 Interview Question
1:37 Writing the Queries
2:40 Inner Join Method
5:33 CTE Method
7:00 Window Function Method
You can recreate the table with this:
CREATE TABLE grades (
`Id` INTEGER,
`name` VARCHAR(5),
`subject_name` VARCHAR(9),
`marks` INTEGER
);
INSERT INTO grades
(`Id`, `name`, `subject_name`, `marks`)
VALUES
('1', 'Rob', 'Maths', '30'),
('2', 'White', 'English', '50'),
('3', 'Mark', 'Maths', '70'),
('4', 'David', 'English', '40'),
('5', 'Smith', 'Chemistry', '80'),
('6', 'Greg', 'Maths', '20'),
('7', 'Will', 'English', '45');

Пікірлер: 15
@shubhjais8753
@shubhjais8753 Жыл бұрын
I tried with partition by: select subject, id, marks, max(marks) over(partition by subject order by subject) as max_marks, count(subject) over(partition by subject order by subject) as participents from score ▶ #i used table name as score
@ericaleverson9430
@ericaleverson9430 Жыл бұрын
I like the Windows function option. Less code and more readable.
@blinquedu2
@blinquedu2 5 ай бұрын
hi thanks for the video... I just come up with a new ideia of query using correlated sub-query + cte applying inner join :with student as ( select subject_name, count(*) as participants from students group by subject_name ) select a.subject_name, a.id, a.marks, (select max(marks) from students b where b.subject_name = a.subject_name) as max_marks, c.participants from students a join student c on c.subject_name = a.subject_name
@absentdata
@absentdata 5 ай бұрын
That is a great solution!
@nigereast3796
@nigereast3796 Жыл бұрын
I think from a BI perspective , The last query is optimal
@amazingriknow5986
@amazingriknow5986 Жыл бұрын
Hi, Kindly include table creation and value insertion script in description
@absentdata
@absentdata Жыл бұрын
Added Table Insertion Script.
@amazingriknow5986
@amazingriknow5986 Жыл бұрын
@@absentdata thank you
@yusufbas035
@yusufbas035 Жыл бұрын
hi thank you for your videos I have been watching your videos for 9 months it helps a lot.
@absentdata
@absentdata Жыл бұрын
Happy to help!
@user-wx3dn3il2f
@user-wx3dn3il2f Жыл бұрын
Thnk you! first i've thoght that choice 3 you are using. but i need to always tweak the way of querying this data! thank you for your information with different point of view!
@absentdata
@absentdata Жыл бұрын
Glad you good a new viewpoint. Share the video went anyone you think it will help.
@XxR0cAF3llaxX
@XxR0cAF3llaxX 3 ай бұрын
What was the actual question? We have the Table along with the Result Table that they wanted the applicants to produce, by looking at the result Table i have no idea what the implied question would be. I would have been screened out real quick lol
@method341
@method341 Жыл бұрын
What is id here? The primary key? The student id? The subject id? I'm confused 😂
@absentdata
@absentdata Жыл бұрын
yes you can treat the ID as a unique identifier
SQL performance tuning and query optimization using execution plan
49:23
Zombie Boy Saved My Life 💚
00:29
Alan Chikin Chow
Рет қаралды 20 МЛН
小丑把天使丢游泳池里#short #angel #clown
00:15
Super Beauty team
Рет қаралды 46 МЛН
Learn GROUP BY vs PARTITION BY in SQL
14:03
Anthony Smoak
Рет қаралды 35 М.
Learn SQL + Database Concepts in 20 Minutes
24:34
Chandoo
Рет қаралды 49 М.
SQL Interview Problem asked during Amazon Interview
15:15
techTFQ
Рет қаралды 23 М.