Skip to content

Commit ec26bba

Browse files
committed
Upload 175
1 parent fa83d56 commit ec26bba

File tree

2 files changed

+76
-1
lines changed

2 files changed

+76
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!-- markdownlint-disable MD041 -->
22
[![eevveerryyddaayy release](https://img.shields.io/badge/eevveerryyddaayy-v1.3.0-blue.svg)](https://github.com/ggeerraarrdd/eevveerryyddaayy/)
3-
[![Solved](https://img.shields.io/badge/solved-174-green.svg)](#index)
3+
[![Solved](https://img.shields.io/badge/solved-175-green.svg)](#index)
44
<!-- markdownlint-enable MD041 -->
55

66
# SQL Everyday
@@ -208,6 +208,7 @@ Because this project necessitated a framework to enable consistent daily practic
208208
| 172 | [Create a Session Bar Chart](https://leetcode.com/problems/create-a-session-bar-chart/description/) | [Solution](solutions/172_create_a_session_bar_chart.md) | LeetCode | Easy | Histogram bins w/ `UNION`, `CASE` |
209209
| 173 | [Customers Who Bought Products A and B but Not C](https://leetcode.com/problems/customers-who-bought-products-a-and-b-but-not-c/description/) | [Solution](solutions/173_customers_who_bought_products_a_and_b_but_not_c.md) | LeetCode | Medium | `STRING_AGG` |
210210
| 174 | [Highest Salaries Difference](https://leetcode.com/problems/highest-salaries-difference/description/) | [Solution](solutions/174_highest_salaries_difference.md) | LeetCode | Easy | |
211+
| 175 | [Form a Chemical Bond](https://leetcode.com/problems/form-a-chemical-bond/description/) | [Solution](solutions/175_form_a_chemical_bond.md) | LeetCode | Easy | `CROSS JOIN` |
211212
<!-- Index End - WARNING: Do not delete or modify this markdown comment. -->
212213
<!--- cSpell:enable --->
213214

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# SQL Everyday \#175
2+
3+
## Form a Chemical Bond
4+
5+
Site: LeetCode\
6+
Difficulty per Site: Easy
7+
8+
## Problem
9+
10+
Two elements can form a bond if one of them is `'Metal'` and the other is `'Nonmetal'`.
11+
12+
Write a solution to find all the pairs of elements that can form a bond.
13+
14+
Return the result table **in any order**. [[Full Description](https://leetcode.com/problems/form-a-chemical-bond/description/)]
15+
16+
## Submitted Solution
17+
18+
```sql
19+
-- Submitted Solution
20+
-- Write your PostgreSQL query statement below
21+
WITH noble AS (
22+
SELECT
23+
symbol
24+
FROM Elements
25+
WHERE type = 'Metal'
26+
),
27+
nonmetal AS (
28+
SELECT
29+
symbol
30+
FROM Elements
31+
WHERE type = 'Nonmetal'
32+
)
33+
SELECT
34+
n.symbol AS metal
35+
,nm.symbol AS nonmetal
36+
FROM noble AS n
37+
CROSS JOIN nonmetal AS nm
38+
;
39+
```
40+
41+
## Site Solution
42+
43+
```sql
44+
-- LeetCode Solution
45+
-- Using JOIN + Filtering
46+
-- Code Author Naveen Kumar Vadlamudi
47+
-- https://leetcode.com/problems/form-a-chemical-bond/solutions/2850891/solution-using-join-filtering
48+
49+
SELECT M.SYMBOL AS METAL, NM.SYMBOL AS NONMETAL
50+
FROM
51+
( SELECT SYMBOL FROM ELEMENTS AS E WHERE E.TYPE = 'Metal' ) AS M ,
52+
( SELECT SYMBOL FROM ELEMENTS AS E WHERE E.TYPE = 'Nonmetal' ) AS NM
53+
54+
-- Code Author Lalit Das
55+
-- https://leetcode.com/problems/form-a-chemical-bond/solutions/2845961/cross-join-with-condition
56+
select
57+
a.symbol as metal,
58+
b.symbol as nonmetal
59+
from
60+
Elements as a,
61+
Elements as b
62+
where a.type= "Metal" and b.type="Nonmetal"
63+
```
64+
65+
## Notes
66+
67+
TBD
68+
69+
## NB
70+
71+
`CROSS JOIN`
72+
73+
Go to [Index](../?tab=readme-ov-file#index)\
74+
Go to [Overview](../?tab=readme-ov-file)

0 commit comments

Comments
 (0)