回答編集履歴
1
追加
test
CHANGED
@@ -53,3 +53,59 @@
|
|
53
53
|
and not_a is not null
|
54
54
|
|
55
55
|
```
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
# 追加
|
60
|
+
|
61
|
+
```SQL
|
62
|
+
|
63
|
+
create table user(name varchar(10),age int, sex set('男','女'));
|
64
|
+
|
65
|
+
insert into user values
|
66
|
+
|
67
|
+
('Bさん',20,'男'),
|
68
|
+
|
69
|
+
('Cさん',30,'女');
|
70
|
+
|
71
|
+
```
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
- ユーザー情報つき
|
76
|
+
|
77
|
+
```SQL
|
78
|
+
|
79
|
+
select * from (
|
80
|
+
|
81
|
+
select no,dat,elt(field('Aさん',to_user,from_user),from_user,to_user) as not_a
|
82
|
+
|
83
|
+
from tbl as t1
|
84
|
+
|
85
|
+
having not exists(select 1
|
86
|
+
|
87
|
+
from tbl
|
88
|
+
|
89
|
+
where 'Aさん' in(to_user,from_user)
|
90
|
+
|
91
|
+
and elt(field('Aさん',to_user,from_user),from_user,to_user)=not_a
|
92
|
+
|
93
|
+
and dat>t1.dat
|
94
|
+
|
95
|
+
)
|
96
|
+
|
97
|
+
and not_a is not null
|
98
|
+
|
99
|
+
)
|
100
|
+
|
101
|
+
as t2
|
102
|
+
|
103
|
+
inner join user as t3 on t2.not_a=t3.name
|
104
|
+
|
105
|
+
```
|
106
|
+
|
107
|
+
※上記だとDさんがuserテーブルにないので消えてしまいます
|
108
|
+
|
109
|
+
ユーザー情報のないuserもnullで個人情報を表示したいなら
|
110
|
+
|
111
|
+
inner joinをleft joinに変えてください
|