No video

Super Interesting SQL Problem | Practice SQL Queries

  Рет қаралды 22,366

techTFQ

techTFQ

Күн бұрын

This video will solve a complex SQL Query shared in my discord server. It's an SQL Problem where we must transform the given list of arbitrary values in a specific format. This can be a potential SQL Interview problem for experienced candidates.
THANK YOU for watching!

Пікірлер: 55
@GamerShaggy
@GamerShaggy 2 ай бұрын
create table arbitrary_values (name varchar(500)); insert into arbitrary_values values ('a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21');
@GamerShaggy
@GamerShaggy 2 ай бұрын
with recursive cte as ( select *, 1 as iter, max(idx) over() as max_idx from cte_values where idx = 1 union select cv.*, (iter + 1) as iter, max(cv.idx) over() as max_idx from cte join cte_values cv on cv.idx between (max_idx + 1) and (max_idx + 1 + iter)), cte_values as ( select x.* from arbitrary_values cross join unnest(string_to_array(name, ', ')) with ordinality x(val, idx)) select iter as group, string_agg(val, ', ') as string_value from cte group by iter order by iter;
@Naveenvuppala
@Naveenvuppala 2 ай бұрын
Watching your videos from 2 years. Understood and thanks...
@KoushikT
@KoushikT 2 ай бұрын
Its pretty difficult to know all these functions in a real life interview considering we are seeing this problem for the first time, wondering who would ask such a question
@Naveenvuppala
@Naveenvuppala 2 ай бұрын
Correct
@SanjayKumar-sr5ft
@SanjayKumar-sr5ft 2 ай бұрын
Exactly This video is good for knowing that such things do exist 😂
@observer698
@observer698 Ай бұрын
I think setting the bar so high is always good, then when simple questions are asked we can be very confident solving them
@rohitsethi5696
@rohitsethi5696 Ай бұрын
with test as ( SELECT row_number() over(order by name) idx, value val FROM arbitrary_values CROSS APPLY STRING_SPLIT(name, ',') ) ,cte as ( select *,1 as iter,max(idx) over() as max_idx from test where idx=1 union all select cv.*,(iter+1) as iter,max(cv.idx) over() as max_idx from cte join test cv on cv.idx between max_idx+1 and max_idx+1+iter) select iter as grp,string_agg(val,',') from cte group by iter order by iter
@sravankumar1767
@sravankumar1767 2 ай бұрын
Very tricky question but you made very easy . Superb explanation 👌 👏 👍
@karunpreetsoni6090
@karunpreetsoni6090 2 ай бұрын
Amazing Logic...!! Totally appreciate your efforts
@kamalakant05
@kamalakant05 2 ай бұрын
Awesome work, you are just amazing. May Allah bless you.
@swetasuman4498
@swetasuman4498 2 ай бұрын
Thanks Sir!! Best channel to learn SQL.
@s.v.dhanalakshmi8771
@s.v.dhanalakshmi8771 2 ай бұрын
Hi TFQ, Thank you so much for all your Sql videos…. You r really great I have watched all your Sql videos and now become a good at Sql also I got a new job with good package all credits goes to you…. Thank you once again you are doing a amazing job
@anujshrigiriwar2901
@anujshrigiriwar2901 2 ай бұрын
Super interesting !! Thanks for educating us.
@bhavitavyashrivastava8600
@bhavitavyashrivastava8600 17 күн бұрын
awesome explanation
@RaviTheVlogger
@RaviTheVlogger 2 ай бұрын
Well explained. Super clear.
@Alexpudow
@Alexpudow 2 ай бұрын
Ms sql solve with rec as ( select 'a' a, 1 b union all select 'a' a, b+1 from rec where b+1
@bhavitavyashrivastava8600
@bhavitavyashrivastava8600 17 күн бұрын
Why are the last two rows not coming as it should? Please clarify WITH cte_values AS ( SELECT x.val, (ROW_NUMBER() OVER ()) - 1 AS row_num FROM arbitrary_values CROSS JOIN UNNEST(string_to_array(name, ', ')) WITH ORDINALITY AS x(val, idx) ), grouped_values AS ( SELECT val, FLOOR((SQRT(8 * (row_num) + 1) - 1) / 2) AS grp Formula to calculate the group number FROM cte_values )
@malleswarasingam3427
@malleswarasingam3427 2 ай бұрын
Hi Toufiq, can you please plan a series where you explain regarding reading the json file through SQL. Thanx in advance
@iswillia123
@iswillia123 Ай бұрын
I did it this way in Oracle. with cte as ( select level lev from arbitrary_values connect by level
@premakolia
@premakolia 2 ай бұрын
never seen join on between...whatta heil
@observer698
@observer698 Ай бұрын
same !!! he is like playing magic with SQL! :D
@sztap
@sztap 2 ай бұрын
Love this, a masterpiece.
@btemghare
@btemghare 2 ай бұрын
Thank you for sharing
@sagargaud8460
@sagargaud8460 17 күн бұрын
What is CTE Why its getting difficult for me to understand i complete position of mysql
@Preeti_kapoorpura
@Preeti_kapoorpura 2 ай бұрын
I learn sql plzz make vedio for beginners...
@tteejjj
@tteejjj 2 ай бұрын
Real time use hai iss ka ??? But useful for logical problem 👍🏻
@atulsingh647
@atulsingh647 2 ай бұрын
Hi @techTFQ Could you please solve below query? item price Quantity pencil 200 20 book 150 3 pen 150 3 Yo have 300$ only, below s the output: price quantity 300 22
@MeghanMoore-oe4tq
@MeghanMoore-oe4tq Күн бұрын
Anderson Daniel Walker Anthony Hernandez Elizabeth
@winstongraves8321
@winstongraves8321 2 ай бұрын
Great vid
@sunilrao6090
@sunilrao6090 2 ай бұрын
sir, how to do it in mysql, especially string to array
@chetanrajput6081
@chetanrajput6081 2 ай бұрын
Python : Welcome to the team , Sql.
@siddhant7953
@siddhant7953 2 ай бұрын
Input:1234567890 Output: ****56**** Please solve this by SQL
@SaurabhSingh-kr9db
@SaurabhSingh-kr9db 2 ай бұрын
are you going to launch SQL course ..Please share
@mahi_sz
@mahi_sz 2 ай бұрын
loved it vro
@Lolfy23
@Lolfy23 2 ай бұрын
But this is not working in T-SQL
@vishnugottipati9373
@vishnugottipati9373 2 ай бұрын
Ms sql server plz
@anandreddy9591
@anandreddy9591 2 ай бұрын
Sir, can we do the the same sql server,if yes wt is the function used
@satyajitbiswal6162
@satyajitbiswal6162 2 ай бұрын
create table arbitrary_values (name varchar(500)); insert into arbitrary_values values ('a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20,a21'); with cte as (select value as k from arbitrary_values cross apply string_split(name,',')), cte2 as (select k,1 as cnt,1 as num from cte where k='a1' union all select b.k,case when a.num
@AgnesCarpenter-p1o
@AgnesCarpenter-p1o 8 күн бұрын
Robinson Sandra Wilson Anthony Anderson Daniel
@djsahu98
@djsahu98 2 ай бұрын
Can this be solved in MS SQL server?
@satyajitbiswal6162
@satyajitbiswal6162 2 ай бұрын
create table arbitrary_values (name varchar(500)); insert into arbitrary_values values ('a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20,a21'); with cte as (select value as k from arbitrary_values cross apply string_split(name,',')), cte2 as (select k,1 as cnt,1 as num from cte where k='a1' union all select b.k,case when a.num
@sajidbhati4946
@sajidbhati4946 2 ай бұрын
Here is my logic instead of printing row number like this {1,2,3,4,5..} i printed them {1,2,2,3,3,3,4,4,4,4.....} and then grouped them --> with cte as ( SELECT FLOOR((SQRT(8*(row_number()over() -1) + 1) - 1) / 2) + 1 AS group_num, name FROM ( SELECT unnest(string_to_array(name, ',')) AS name FROM arbitrary_values ) AS split_names) select group_num,string_agg(name,' , ') from cte group by group_num order by group_num;
@funhelmet2102
@funhelmet2102 2 ай бұрын
Group_concat()
@sravankumar1767
@sravankumar1767 2 ай бұрын
WITH NumberedIDs AS ( SELECT id, ROW_NUMBER() OVER (ORDER BY value ) AS row_num FROM your table ), GroupedIDs AS ( SELECT id, CASE WHEN row_num % 3 = 1 THEN row_num WHEN row_num % 3 = 2 THEN row_num - 1 WHEN row_num % 3 = 0 THEN row_num - 2 END AS group_id FROM NumberedIDs ) SELECT group_id, STRING_AGG(value, ', ') WITHIN Group (order by value) as Value FROM GroupedIDs GROUP BY group_id
@satyajitbiswal6162
@satyajitbiswal6162 2 ай бұрын
this will not give correct result
@sravankumar1767
@sravankumar1767 2 ай бұрын
Can you please answer this question in MS sql server
@Odiajhiajyoti
@Odiajhiajyoti 2 ай бұрын
Sir please help me i have not cracked interview
@leoadam6492
@leoadam6492 2 ай бұрын
Can you share the question they asked
@tolulopeesho852
@tolulopeesho852 2 ай бұрын
Hello Thoufiq, Thank you so much for your videos. Please I tried this in the SQL server but my recursion did not terminate. Here is the query below: With AData as (Select Row_number() Over (Order By (select 0)) as RwNum, Value From ArbitraryData Cross apply String_Split(items, ',')), ArrData (Value, n, RwNum, MaxR) as (Select Value, 1 as n, RwNum, Max(RwNum) Over() as MaxR from AData where RwNum = 1 Union all Select Ad.Value, (n+1) as n, Ad.RwNUM, Max(Ad.RwNum) Over() as MaxR From ArrData Join AData AD ON Ad.RwNum between MaxR+1 and MaxR+1+n) Select * From ArrData Thank you!
@viveks288
@viveks288 2 ай бұрын
Hi sir, the question asked for Accolite company please give me the answer sir input: tab_abc-----table name order entity ---- column xyz 5 -- values pqr 7 -- values write a insert statement for entity value times output: tab_pzn -----table name order ---- column xyz -- values xyz . xyz . xyz xyz . pqr . pqr . pqr pqr pqr pqr -- values
Unveiling my winning secret to defeating Maxim!😎| Free Fire Official
00:14
Garena Free Fire Global
Рет қаралды 9 МЛН
Cute kitty gadgets 💛
00:24
TheSoul Music Family
Рет қаралды 15 МЛН
ISSEI & yellow girl 💛
00:33
ISSEI / いっせい
Рет қаралды 24 МЛН
SQL Indexes Explained in 20 Minutes
19:31
developedbyed
Рет қаралды 9 М.
REAL SQL Interview Problem | Hierarchical data in SQL
22:09
The Harsh Reality of Being a Data Analyst
7:39
Sundas Khalid
Рет қаралды 581 М.
6 SQL Joins you MUST know! (Animated + Practice)
9:47
Anton Putra
Рет қаралды 144 М.