Leetcode Problem 2480. Form a Chemical Bond

2480. Form a Chemical Bond

Leetcode Solutions

Cross Join with Filtering

  • Start by selecting all columns from the Elements table and alias it as a.
  • Perform a cross join with the Elements table itself, aliasing the second instance as b.
  • Apply a WHERE clause to filter the results where a.type is 'Metal' and b.type is 'Nonmetal'.
  • Select a.symbol as metal and b.symbol as nonmetal from the filtered results to get the desired output.

erDiagram
    ELEMENTS {
        varchar symbol PK
        enum type
        int electrons
    }

Using JOIN with Subqueries for Filtering

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...