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