 Hello, welcome to SSHiritec Social Decide and this is continuation of SIKO-Savoy interview questions and answers. So today we are going to discuss two more interview questions and these are very important. So as we can see considered P1 as A, B and P2 as C, D to be two points in a 2D plane. So here as we can see we have input table and it would have total five columns first is ID, city, state, Latin and Long W. So we have total five columns. So write a query to get the Manhattan distance between P1 and P2 and round it to a scale of four decimal places. So how we can calculate the Manhattan distance? So for that we have to calculate C-A plus D-B. So what is C-A, D and B? So A happens to equal the minimum value of Latin in station table. Next B it is the minimum value of Long W then C is the maximum value of Latin and D is the maximum value of Long W. So here we have to use C that is the maximum value of Latin then minus A that is minimum value of Latin then plus maximum value of Long W minus minimum value of Long W. So how we can write the query for getting the output of Manhattan distance? So let us move to SQL Server Management Studio where we will write the query for getting this output. So as I am using SQL 2017 you may have another version of SQL Server. So first of all let me execute the create table statement to create the table. So as we can see command completed successfully so table is created successfully. Next I just want to insert record on this table so we can execute insert statement. So data is inserted successfully on this table. Next I just want to check the data. So for that we can use select a stick from our table that is station. Now let me execute the selected statement. So here we are having the data. So what was the logic for calculating Manhattan distance? First we have to calculate the maximum value of Latin. So this is maximum value then minus minimum value of Latin. So this is the minimum value of Latin and we need to close this into bracket. Next we need to add maximum value of long w minus minimum value of long w. So it is going to return the Manhattan distance. Now let me execute and check the output. So here we are getting 8.33387000 but what our question was we need to get the up to 4 decimal places. So we have to use cast then as then numeric and this would be 14 comma 4. Now let me execute and check the output. So here we are getting 8.3339 and we can check we are having 8339. So we are getting the output as we are expecting. Let's move to next question. So here we need to calculate the Euclidean distance. So for that let's consider p1 as a comma c and p2 b comma d to be 2 points in 2d plane where a comma b are the respective minimum and maximum value of Latin and c comma d are minimum and maximum value of long w. And again here how we can write the query to get the output and again we need to get the output up to 4 decimal places only. So this is the formula by which we can calculate the Euclidean distance. So as we can see first of all q1 minus p1. So for that we can see over here we have b then a. So we need to subtract b minus a then square plus d minus c then square and whole root. So we need to apply this formula. So what is b minus a? So here we can see maximum value of Latin and minimum value of Latin then cd minimum and maximum value for long w. So how we can write the query for getting the output. So let's move to Ccosso management studio where we will write the query for getting the output. So here first of all I would like to execute the create table statement to create the table. So as we can see table is created successfully then I want to insert record on this table so we can execute this inserted statement. Now I just want to check the value inside this table. So we can write select as tick from our table that is station. Now let me execute. So here we are getting the data but we need to calculate the Euclidean distance. So for that we need to get the maximum value of Latin minus minimum value of Latin. Then we need to use this as square and then we need to put this inside the bracket. Next we need to add the same thing for the long w. So how we can get here we need to use the maximum value for long w minus minimum value of long w and this value should be square. So as we can see in the formula we are having q1 minus p1 square plus q2 minus p2 square. So we have done this part next we need to use the square root. So here we can use the square root of this value. So we can close this value. Now let me execute the query and check the output. So here we are getting 5.89830 something like this but our requirement we just want to get data up to four different places. So we have to use cast then as numeric 14.4 now let me execute and check the output. So here we are getting 5.8983 and in the output 5.8983. So we are getting the output as we are expecting. So thank you so much for watching this video. I hope you have understand how we can get the Manhattan distance and Euclidean distance. So if you like this video please subscribe our channel to get many more videos. Don't forget to press the bell icon to get the notification of our newly uploaded videos. Thank you so much for watching this video.