File tree 15 files changed +134
-150
lines changed
0612.Shortest Distance in a Plane
0613.Shortest Distance in a Line
15 files changed +134
-150
lines changed Original file line number Diff line number Diff line change 13
13
14
14
<!-- tabs:start -->
15
15
16
- ### ** Python3**
17
- <!-- 这里可写当前语言的特殊实现逻辑 -->
16
+ ### ** SQL**
18
17
19
- ``` python
20
-
21
- ```
22
-
23
- ### ** Java**
24
- <!-- 这里可写当前语言的特殊实现逻辑 -->
25
-
26
- ``` java
27
-
28
- ```
29
-
30
- ### ** ...**
31
18
```
32
-
19
+ SELECT name
20
+ FROM salesperson
21
+ WHERE sales_id NOT IN
22
+ (SELECT sales_id
23
+ FROM orders
24
+ WHERE com_id =
25
+ (SELECT com_id
26
+ FROM company
27
+ WHERE name = 'RED'))
33
28
```
34
29
35
- <!-- tabs:end -->
30
+ <!-- tabs:end -->
Original file line number Diff line number Diff line change 11
11
12
12
<!-- tabs:start -->
13
13
14
- ### ** Python3 **
14
+ ### ** SQL **
15
15
16
- ``` python
17
-
18
- ```
19
-
20
- ### ** Java**
21
-
22
- ``` java
23
-
24
- ```
25
-
26
- ### ** ...**
27
16
```
28
-
17
+ SELECT name
18
+ FROM salesperson
19
+ WHERE sales_id NOT IN
20
+ (SELECT sales_id
21
+ FROM orders
22
+ WHERE com_id =
23
+ (SELECT com_id
24
+ FROM company
25
+ WHERE name = 'RED'))
29
26
```
30
27
31
- <!-- tabs:end -->
28
+ <!-- tabs:end -->
Original file line number Diff line number Diff line change
1
+ SELECT name
2
+ FROM salesperson
3
+ WHERE sales_id NOT IN
4
+ (SELECT sales_id
5
+ FROM orders
6
+ WHERE com_id =
7
+ (SELECT com_id
8
+ FROM company
9
+ WHERE name = ' RED' ))
Original file line number Diff line number Diff line change 13
13
14
14
<!-- tabs:start -->
15
15
16
- ### ** Python3**
17
- <!-- 这里可写当前语言的特殊实现逻辑 -->
16
+ ### ** SQL**
18
17
19
- ``` python
20
-
21
- ```
22
-
23
- ### ** Java**
24
- <!-- 这里可写当前语言的特殊实现逻辑 -->
25
-
26
- ``` java
27
-
28
- ```
29
-
30
- ### ** ...**
31
18
```
32
-
19
+ SELECT id AS Id,
20
+
21
+ CASE
22
+ WHEN p_id is NULL THEN
23
+ 'Root'
24
+ WHEN id IN
25
+ (SELECT p_id
26
+ FROM tree
27
+ WHERE p_id is NOT null) THEN
28
+ 'Inner'
29
+ ELSE 'Leaf'
30
+ END AS Type
31
+ FROM tree
33
32
```
34
33
35
- <!-- tabs:end -->
34
+ <!-- tabs:end -->
Original file line number Diff line number Diff line change 11
11
12
12
<!-- tabs:start -->
13
13
14
- ### ** Python3 **
14
+ ### ** SQL **
15
15
16
- ``` python
17
-
18
- ```
19
-
20
- ### ** Java**
21
-
22
- ``` java
23
-
24
- ```
25
-
26
- ### ** ...**
27
16
```
28
-
17
+ SELECT id AS Id,
18
+
19
+ CASE
20
+ WHEN p_id is NULL THEN
21
+ 'Root'
22
+ WHEN id IN
23
+ (SELECT p_id
24
+ FROM tree
25
+ WHERE p_id is NOT null) THEN
26
+ 'Inner'
27
+ ELSE 'Leaf'
28
+ END AS Type
29
+ FROM tree
29
30
```
30
31
31
- <!-- tabs:end -->
32
+ <!-- tabs:end -->
Original file line number Diff line number Diff line change
1
+ SELECT id AS Id,
2
+
3
+ CASE
4
+ WHEN p_id is NULL THEN
5
+ ' Root'
6
+ WHEN id IN
7
+ (SELECT p_id
8
+ FROM tree
9
+ WHERE p_id is NOT null ) THEN
10
+ ' Inner'
11
+ ELSE ' Leaf'
12
+ END AS Type
13
+ FROM tree
Original file line number Diff line number Diff line change 13
13
14
14
<!-- tabs:start -->
15
15
16
- ### ** Python3**
17
- <!-- 这里可写当前语言的特殊实现逻辑 -->
16
+ ### ** SQL**
18
17
19
- ``` python
20
-
21
- ```
22
-
23
- ### ** Java**
24
- <!-- 这里可写当前语言的特殊实现逻辑 -->
25
-
26
- ``` java
27
-
28
- ```
29
-
30
- ### ** ...**
31
18
```
32
-
19
+ SELECT x,
20
+ y,
21
+ z,
22
+ if(x + y > z
23
+ AND x + z > y
24
+ AND y + z > x, "Yes", "No") AS triangle
25
+ FROM triangle
33
26
```
34
27
35
- <!-- tabs:end -->
28
+ <!-- tabs:end -->
Original file line number Diff line number Diff line change 11
11
12
12
<!-- tabs:start -->
13
13
14
- ### ** Python3 **
14
+ ### ** SQL **
15
15
16
- ``` python
17
-
18
- ```
19
-
20
- ### ** Java**
21
-
22
- ``` java
23
-
24
- ```
25
-
26
- ### ** ...**
27
16
```
28
-
17
+ SELECT x,
18
+ y,
19
+ z,
20
+ if(x + y > z
21
+ AND x + z > y
22
+ AND y + z > x, "Yes", "No") AS triangle
23
+ FROM triangle
29
24
```
30
25
31
- <!-- tabs:end -->
26
+ <!-- tabs:end -->
Original file line number Diff line number Diff line change
1
+ SELECT x,
2
+ y,
3
+ z,
4
+ if(x + y > z
5
+ AND x + z > y
6
+ AND y + z > x, " Yes" , " No" ) AS triangle
7
+ FROM triangle
Original file line number Diff line number Diff line change 13
13
14
14
<!-- tabs:start -->
15
15
16
- ### ** Python3**
17
- <!-- 这里可写当前语言的特殊实现逻辑 -->
16
+ ### ** SQL**
18
17
19
- ``` python
20
-
21
- ```
22
-
23
- ### ** Java**
24
- <!-- 这里可写当前语言的特殊实现逻辑 -->
25
-
26
- ``` java
27
-
28
- ```
29
-
30
- ### ** ...**
31
18
```
32
-
19
+ SELECT round(min(sqrt(power(p1.x-p2.x,
20
+ 2) + power(p1.y-p2.y,
21
+ 2))),
22
+ 2) shortest
23
+ FROM point_2d p1, point_2d p2
24
+ WHERE (p1.x, p1.y) <> (p2.x,p2.y)
33
25
```
34
26
35
- <!-- tabs:end -->
27
+ <!-- tabs:end -->
Original file line number Diff line number Diff line change 11
11
12
12
<!-- tabs:start -->
13
13
14
- ### ** Python3 **
14
+ ### ** SQL **
15
15
16
- ``` python
17
-
18
- ```
19
-
20
- ### ** Java**
21
-
22
- ``` java
23
-
24
- ```
25
-
26
- ### ** ...**
27
16
```
28
-
17
+ SELECT round(min(sqrt(power(p1.x-p2.x,
18
+ 2) + power(p1.y-p2.y,
19
+ 2))),
20
+ 2) shortest
21
+ FROM point_2d p1, point_2d p2
22
+ WHERE (p1.x, p1.y) <> (p2.x,p2.y)
29
23
```
30
24
31
- <!-- tabs:end -->
25
+ <!-- tabs:end -->
Original file line number Diff line number Diff line change
1
+ SELECT round(min (sqrt(power(p1 .x - p2 .x ,
2
+ 2 ) + power(p1 .y - p2 .y ,
3
+ 2 ))),
4
+ 2 ) shortest
5
+ FROM point_2d p1, point_2d p2
6
+ WHERE (p1 .x , p1 .y ) <> (p2 .x ,p2 .y )
Original file line number Diff line number Diff line change 13
13
14
14
<!-- tabs:start -->
15
15
16
- ### ** Python3**
17
- <!-- 这里可写当前语言的特殊实现逻辑 -->
16
+ ### ** SQL**
18
17
19
- ``` python
20
-
21
- ```
22
-
23
- ### ** Java**
24
- <!-- 这里可写当前语言的特殊实现逻辑 -->
25
-
26
- ``` java
27
-
28
- ```
29
-
30
- ### ** ...**
31
18
```
32
-
19
+ SELECT min(abs(p1.x-p2.x)) shortest
20
+ FROM point p1, point p2
21
+ WHERE p1.x != p2.x
33
22
```
34
23
35
- <!-- tabs:end -->
24
+ <!-- tabs:end -->
Original file line number Diff line number Diff line change 11
11
12
12
<!-- tabs:start -->
13
13
14
- ### ** Python3 **
14
+ ### ** SQL **
15
15
16
- ``` python
17
-
18
- ```
19
-
20
- ### ** Java**
21
-
22
- ``` java
23
-
24
- ```
25
-
26
- ### ** ...**
27
16
```
28
-
17
+ SELECT min(abs(p1.x-p2.x)) shortest
18
+ FROM point p1, point p2
19
+ WHERE p1.x != p2.x
29
20
```
30
21
31
- <!-- tabs:end -->
22
+ <!-- tabs:end -->
Original file line number Diff line number Diff line change
1
+ SELECT min (abs(p1 .x - p2 .x )) shortest
2
+ FROM point p1, point p2
3
+ WHERE p1 .x != p2 .x
You can’t perform that action at this time.
0 commit comments