You are given a table Elements that contains information about chemical elements.
The table has the following structure:
symbol(varchar): Primary key representing the element symboltype(enum): The type of element - 'Metal', 'Nonmetal', or 'Noble'electrons(int): Number of electrons the element can give or needs
Rules:
- If
typeis 'Noble',electronsis 0 - If
typeis 'Metal',electronsis the number of electrons that one atom can give - If
typeis 'Nonmetal',electronsis the number of electrons that one atom needs
Chemical Bond Formation: Two elements can form a bond if one is 'Metal' and the other is 'Nonmetal'.
Write a SQL query to find all pairs of elements that can form a chemical bond. Return the result in any order.
Table Schema
| Column Name | Type | Description |
|---|---|---|
symbol
PK
|
varchar | Element symbol (primary key) |
type
|
enum | Element type: 'Metal', 'Nonmetal', or 'Noble' |
electrons
|
int | Electrons given (Metal) or needed (Nonmetal), 0 for Noble |
Input & Output
| symbol | type | electrons |
|---|---|---|
| Na | Metal | 1 |
| Cl | Nonmetal | 1 |
| He | Noble | 0 |
| metal | nonmetal |
|---|---|
| Na | Cl |
Sodium (Na) is a metal that can give 1 electron, and Chlorine (Cl) is a nonmetal that needs 1 electron. They can form an ionic bond. Helium (He) is a noble gas and cannot form bonds with other elements.
| symbol | type | electrons |
|---|---|---|
| Li | Metal | 1 |
| Ca | Metal | 2 |
| F | Nonmetal | 1 |
| O | Nonmetal | 2 |
| metal | nonmetal |
|---|---|
| Ca | F |
| Ca | O |
| Li | F |
| Li | O |
All metals (Li, Ca) can form bonds with all nonmetals (F, O), regardless of their electron counts. The result shows all possible Metal-Nonmetal pairs sorted alphabetically.
| symbol | type | electrons |
|---|---|---|
| Ne | Noble | 0 |
| Ar | Noble | 0 |
| metal | nonmetal |
|---|
Only noble gases are present in the table. Since bonds can only form between metals and nonmetals, no chemical bonds are possible, resulting in an empty result set.
Constraints
-
1 ≤ number of elements ≤ 100 -
typeis one of'Metal','Nonmetal', or'Noble' -
0 ≤ electrons ≤ 8 -
symbolconsists of 1-2 uppercase letters