Комментарии:
platform to practise advance sql??
Ответитьhi, love your teaching technique, please make a video on advance power bi interview Q&A. it will really appreciated.
thankyou
please comeup with more interview questions (sql) that would be helpful. Thank you
ОтветитьSir, Could u pls tell me in Sub query what is the use of NOT EXISTS Function.....what will this not exists function suppose to do here?pls help
Ответитьselect t1.* from dbo.tdistance t1
inner join dbo.tdistance t2
on t1.source=t2.destination and t1.destination=t2.source and t1.destination>t2.destination
using sub query ,, inside query is giving the same results, then why we need to use outer not exists
ОтветитьHi sir, i am not getting the exact output
ОтветитьSir I am using 1st and 2nd method in Microsoft SQL server and it is showing error. In 2nd method it is saying 'the row_number must have an over clause with order by'. And in 1st method it is showing ' greatest ' is not a recognised built-in function name. Please help me
ОтветитьI came up with a very simple one 😹:
SELECT *
FROM travel
WHERE source > destination
(Though it won't work if we change the question a little by adding a single entry with no reversed entry, Method 2 will also fail in that situation.)
------------------------------------
We can use DISTINCT in Method 1:
SELECT DISTINCT GREATEST(source, destination), LEAST(source, destination), distance FROM travel
Method 3 is nice and creative, took me a couple of minutes to understand.
Learning a lot from you, keep doing it bro. ❤❤❤
If you give the link of the tables in description which you used to solved the problems in this video then it will be better rishabh
ОтветитьMy personal two methods,
M1:
select distance,GROUP_CONCAT(source) from (select distinct * from table) as sub_query
GROUP BY distance; (:: "select distinct * from table" important if you have original duplicates cities pair)
M2:
select DISTINCT greatest(source,destination) as "from",least(source,destination) as "to",distance from table;
In the first approach without doing group by and all,we can just apply distinct after greatest and and least things
ОтветитьI m failed to do also understand
ОтветитьBhaiya direct bhi ho skta h na ye to
Select * from travel Where source>deatination;
Aise
Sir, u have given 3 method bt we can simply write it as follows -
Select * from travel
Where source IN ( Mumbai, mathura, nagpur);
Plz tell me if it is correct?
I go with inner join. Method 2.
Method 3 slightly difficult.
using cte :
with cte1 as
(select source, row_number() over(order by (select null)) as rn_s
from travel
)
select t1.source, t1.destination, t1.distance from travel as t1
join
(
select c1.source as source, c2.source as destination from cte1 c1
join cte1 c2
where c1.source <> c2.source and c1.rn_s < c2.rn_s
) as t2
on t1.source = t2.source and t1.destination = t2.destination ;
sirji third method mein agar dono city same alphabet se start hogi to appka favorite method fail kr jayega (iss table mein it worked) lol!
ОтветитьUsing greatest and least method
select greatest(source,destination),least(source,destination),max(distance)
from travel
group by greatest(source,destination),least(source,destination);
here we can use mod function mod(id,2)=0 actully we can solve many methods but sir you solved very easy way great
ОтветитьCan't understand why the max function is used with distance? We are not using distance in the group by then why is it throwing in an error to add an aggregate function. Is it necessary to add all the called variables while using the group by on any one of them?🤔 Also, why the where not exists is added in third method? ThanQ in advance. @rishabh mishra gr8 going...🖖
ОтветитьDo you have in English version?
Ответитьgreat and excellence sir
ОтветитьMishra ji 🙏, you are wonderful teacher and it is reflected in your videos. 🙂 It is also evident from your prof. experience.
Ответитьfirst method was the easiest...other 2 I did not understand😅
Ответитьsir group by distance kr denge to ho jaega
ОтветитьSELECT source,destination,distance FROM travel WHERE source LIKE 'M%' OR source LIKE 'N%';
ОтветитьBeing from non IT background, If i learn SQL and other required things how i get job ???
ОтветитьI am sorry but I must say beginners will find it hard to understand your Queries
In your 3rd method beginners will gona ask why is there NOT EXISTS clause.
Even after watching your whole SQL playlist 😅
i found out the easiest one
select source, destination, distance FROM travel
WHERE length(source) between 6 and 7
Sir, I enjoyed this session. Great explanation.
I learnt SQL from a course recommended by you in one of your videos. SQL Go from Zero to hero by Jose Portilla. Few concepts were not covered in that course, such as windows functions, greatest, least etc. Can you please tell where can I also learn such concepts?
table download link description mai nhii diya sir?
ОтветитьSir in using self join I am getting only 2 rows of output but as you doing in your slide it's having 3 rows of data
ОтветитьWhy u use not exist in subquery method?
ОтветитьI don't understand the leaste and greatest concept of text not number only text how it work?
Ответитьcode created below.
create table Travel
(
source varchar(20),
destination varchar(20),
distance int8
);
insert into travel
(source,destination,distance)
values
('Mumbai','Bnagalore',500),
('bangalore','Mumbai',500),
('delhi','mathura',150),
('mathura','delhi',150),
('nagpur','pune',500),
('pune','nagpur',500);
select * from travel where source>destination;
is this query right or wrong it show the same result can anyone please explain this query how this is working ????
Method 2 Will not work
If there is duplicate value in either source or destination please have a thought on that
e.g You can add a new record like ('Mumbai', 'Goa', 700) & ('Goa', 'Mumbai', 700) then try this method-2 and it will not work
Please find the code to create the mentioned table in this tutorial:
create table travel (
source varchar(50),
destination varchar(50),
distance varchar(50));
insert into travel (source, destination, distance)
values
('Mumbai', 'Bangalore', 500),
('Bangalore','Mumbai', 500),
('Delhi', 'Mathura', 150),
( 'Mathura','Delhi', 150),
('Nagpur', 'Pune', 500),
( 'Pune','Nagpur', 500);
I solved it this way:
SELECT * FROM travel
WHERE source IN ('Mumbai','Mathura','Nagpur')
is it right ??...coz it is giving the same results
Hi, sir aap data ka file post kr diya kijiye so practice kr sake hmlog
Ответить𝖕𝖗𝖔𝖒𝖔𝖘𝖒 ☹️
ОтветитьSir, Is there any chance of connecting with you over a call?
Ответить