Assistance with using the SQRT function in SQL? Not sure if this is order or parenthesis? Issue with hypotenuse challenge! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Assistance with using the SQRT function in SQL? Not sure if this is order or parenthesis? Issue with hypotenuse challenge!

Running into an issue with the hypotenuse challenge on the SQL course. I can get the square of both sides into 1 column, but I cannot get the SQRT function to work. This is what I have: SELECT side_a * side_a + side_b * side_b as side_c FROM triangle, SQRT (side_c); This code gets me error message on the SQRT function. If I remove the “SQRT(side_c)” I can get “side_c” to print. I’ve tried moving the SQRT function around but I can’t get it print. Any suggestions? Thanks

25th Jan 2021, 12:44 AM
Karsa9Fingers
Karsa9Fingers - avatar
7 Answers
+ 7
Karsa9Fingers Your query is wrong. If you write anything just after FROM it's mean you are pointing to a table so here SQRT(side_c) will be consider as table which is wrong. So your query should look like this SELECT SQRT(side_a * side_a + side_b * side_b) AS "side_c" FROM triangle
25th Jan 2021, 3:16 AM
A͢J
A͢J - avatar
+ 3
Кирилл Чернятин Here side_c is column name. If you want to show result with different column name then you can do like that. You can put according to you.
12th Feb 2021, 3:38 AM
A͢J
A͢J - avatar
+ 2
I Am AJ ! Thank you again sir! i had tried moving to the SQRT function around but couldn’t get it to work. I kept trying to create column “side_c” and then SQRT it, instead of adding SQRT to the equation. Thank you again.
25th Jan 2021, 11:46 AM
Karsa9Fingers
Karsa9Fingers - avatar
+ 1
Кирилл Чернятин For example: suppose you have a table Square with column side_a and you want to show result as side_a, area so what we can do here? We can write our select query like SELECT side_a as "side" , (side_a * side_a) AS "area" FROM Square
12th Feb 2021, 4:28 AM
A͢J
A͢J - avatar
+ 1
I Am AJ ! Thank you for information ! Have a great day ! :).
12th Feb 2021, 6:35 AM
Kirill Chernyatin
Kirill Chernyatin - avatar
0
I Am AJ ! Why is side_c in quotation marks ?
11th Feb 2021, 11:32 PM
Kirill Chernyatin
Kirill Chernyatin - avatar
0
SELECT SQRT(side_a * side_a + side_b * side_b) AS "side_c" FROM triangle
1st Mar 2022, 10:16 AM
Peace Chinonyere