回答編集履歴
4
add and
test
CHANGED
@@ -1,3 +1,27 @@
|
|
1
|
+
Ans
|
2
|
+
|
3
|
+
```
|
4
|
+
|
5
|
+
select * from (
|
6
|
+
|
7
|
+
(select * from `table` where name = 'zirou' order by date asc limit 1)
|
8
|
+
|
9
|
+
union all
|
10
|
+
|
11
|
+
(select * from `table` where name = 'saburou' order by date asc limit 1)
|
12
|
+
|
13
|
+
) as a
|
14
|
+
|
15
|
+
where date >= '2015-02-01 00:00:00'
|
16
|
+
|
17
|
+
and date < '2015-02-03 00:00:00';
|
18
|
+
|
19
|
+
```
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
|
1
25
|
**追記**
|
2
26
|
|
3
27
|
--> の部分のみ抽出したい認識で間違いありませんか?
|
@@ -6,11 +30,11 @@
|
|
6
30
|
|
7
31
|
```
|
8
32
|
|
9
|
-
|
33
|
+
2015/2/1 tarou 5,000
|
10
34
|
|
11
35
|
--> 2015/2/2 zirou 8,000
|
12
36
|
|
13
|
-
2015/2/2 saburou 9,000
|
37
|
+
--> 2015/2/2 saburou 9,000
|
14
38
|
|
15
39
|
2015/2/2 tarou 1,000
|
16
40
|
|
3
Correct Answers mistake.
test
CHANGED
@@ -1,3 +1,31 @@
|
|
1
|
+
**追記**
|
2
|
+
|
3
|
+
--> の部分のみ抽出したい認識で間違いありませんか?
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
```
|
8
|
+
|
9
|
+
--> 2015/2/1 tarou 5,000
|
10
|
+
|
11
|
+
--> 2015/2/2 zirou 8,000
|
12
|
+
|
13
|
+
2015/2/2 saburou 9,000
|
14
|
+
|
15
|
+
2015/2/2 tarou 1,000
|
16
|
+
|
17
|
+
```
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
**下記旧回答**
|
24
|
+
|
25
|
+
---
|
26
|
+
|
27
|
+
|
28
|
+
|
1
29
|
Ans
|
2
30
|
|
3
31
|
```lang-SQL
|
2
Improve readability , unnecessary partial deletion.
test
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
Ans
|
2
|
+
|
1
3
|
```lang-SQL
|
2
4
|
|
3
5
|
select * from table_name
|
@@ -10,35 +12,49 @@
|
|
10
12
|
|
11
13
|
```
|
12
14
|
|
15
|
+
---
|
16
|
+
|
17
|
+
備考
|
13
18
|
|
14
19
|
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
下記のように書く事も可能です。
|
24
|
+
|
15
25
|
```
|
26
|
+
|
27
|
+
select * from table_name
|
28
|
+
|
29
|
+
where date >= '2015-02-01 00:00:00'
|
30
|
+
|
31
|
+
and date <= '2015-02-01 23:59:59'
|
32
|
+
|
33
|
+
and name IN('zero', 'sabre');
|
34
|
+
|
35
|
+
```
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
取得するカラムを絞る例
|
40
|
+
|
41
|
+
```
|
42
|
+
|
43
|
+
select name from table_name
|
16
44
|
|
17
45
|
where date >= '2015-02-01 00:00:00'
|
18
46
|
|
19
47
|
and date < '2015-02-02 00:00:00'
|
20
48
|
|
21
|
-
```
|
22
|
-
|
23
|
-
上記は、2015-02-01 00:00:00 - 2015-02-01 23:59:59と同義と考えて問題ありません。
|
24
|
-
|
25
|
-
その為、下記のようにも書く事が可能です。
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
```
|
30
|
-
|
31
|
-
where date >= '2015-02-01 00:00:00'
|
32
|
-
|
33
|
-
and
|
49
|
+
and name IN('zero', 'sabre');
|
34
50
|
|
35
51
|
```
|
36
52
|
|
37
53
|
|
38
54
|
|
39
|
-
また、betweenを使用した方法
|
55
|
+
また、betweenを使用した方法等、答えは一つではありません。
|
40
56
|
|
41
|
-
|
57
|
+
下記を参考にしてみてください。
|
42
58
|
|
43
59
|
|
44
60
|
|
1
add other sql
test
CHANGED
@@ -8,6 +8,48 @@
|
|
8
8
|
|
9
9
|
and name IN('zero', 'sabre');
|
10
10
|
|
11
|
+
```
|
12
|
+
|
11
13
|
|
12
14
|
|
13
15
|
```
|
16
|
+
|
17
|
+
where date >= '2015-02-01 00:00:00'
|
18
|
+
|
19
|
+
and date < '2015-02-02 00:00:00'
|
20
|
+
|
21
|
+
```
|
22
|
+
|
23
|
+
上記は、2015-02-01 00:00:00 - 2015-02-01 23:59:59と同義と考えて問題ありません。
|
24
|
+
|
25
|
+
その為、下記のようにも書く事が可能です。
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
```
|
30
|
+
|
31
|
+
where date >= '2015-02-01 00:00:00'
|
32
|
+
|
33
|
+
and date <= '2015-02-01 23:59:59'
|
34
|
+
|
35
|
+
```
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
また、betweenを使用した方法もありますのでお好きな手法をご検討ください。
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
**参考**
|
46
|
+
|
47
|
+
MySQL Manual
|
48
|
+
|
49
|
+
http://mysql.stu.edu.tw/doc/refman/5.1/ja/comparison-operators.html
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
betweenを使用してdatetime検索
|
54
|
+
|
55
|
+
http://fukaoi.org/2009/03/19/mysql_datetime
|