SQL and triangles?

Funny little SQL exercise

Simone Rigoni
2 min readNov 27, 2022

I have started using hackerrank.com since a couple of months and I really like it. The website provides cool exercises and preparation kit for interviews.

https://www.google.com/url?sa=i&url=https%3A%2F%2Fwww.oxfordlearnersdictionaries.com%2Fdefinition%2Fenglish%2Ftriangle&psig=AOvVaw3xev1-rSKyW3YDOnpHXa3A&ust=1669635370371000&source=images&cd=vfe&ved=0CBAQjRxqFwoTCLiynsuizvsCFQAAAAAdAAAAABAi

I want to propose you a quick exercise from their SQL section that was pretty funny to do: Type of Triangle

You have to determine the type of triangles contained in a table composed by 3 INT columns (a, b, c). Every row maybe is a triangle and the length of its sides is stored in the a, b and c columns.

Maybe triangles example

Our maybe triangles can be:

  • Equilateral Triangle: all of its sides have equal length
  • Isosceles Triangle: 2 of its sides have equal length
  • Scalene Triangle: all sides have different length
  • Not A Triangle: if the sum of two sides is less than the third one

Before looking at my solution try to do it yourself!

My results

Outro

I hope the story was interesting and thank you for taking the time to read it. Just to be clear I do not have any commercial affiliation with hackerrank.com. On my Blogspot you can find the same post in Italian. Let me know if you have any question and if you like the content that I create feel free to buy me a coffee.

--

--

Simone Rigoni
Simone Rigoni

No responses yet