MySQLの日付の範囲から日を生成するにはどうすればよいですか?
adddate()関数を使用する次のクエリを使用して実行でき、「2016-12-15」から「2016-12-31」までの日数を生成しています。
mysql> select * from
-> (select adddate('1970-01-01',t4*10000 + t3*1000 + t2*100 + t1*10 + t0) gen_date from
-> (select 0 t0 union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t0,
-> (select 0 t1 union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t1,
-> (select 0 t2 union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t2,
-> (select 0 t3 union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t3,
-> (select 0 t4 union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t4) v
-> Where gen_date between '2016-12-15' and '2016-12-31'
-> ;
+------------+
| gen_date |
+------------+
| 2016-12-15 |
| 2016-12-16 |
| 2016-12-17 |
| 2016-12-18 |
| 2016-12-19 |
| 2016-12-20 |
| 2016-12-21 |
| 2016-12-22 |
| 2016-12-23 |
| 2016-12-24 |
| 2016-12-25 |
| 2016-12-26 |
| 2016-12-27 |
| 2016-12-28 |
| 2016-12-29 |
| 2016-12-30 |
| 2016-12-31 |
+------------+
17 rows in set (0.30 sec) -
MySQLビューを使用して、日付の範囲から日を生成するにはどうすればよいですか?
これを説明するために、次のビューを作成しています- mysql> CREATE VIEW digits AS -> SELECT 0 AS digit UNION ALL -> SELECT 1 UNION ALL -> SELECT 2 UNION ALL -> SELECT 3 UNION ALL -> SELECT 4 UNION ALL -> SELECT 5 UNION ALL
-
MySQLから最後の10行を選択するにはどうすればよいですか?
MySQLから最後の10行を選択するには、SELECTステートメントとLimitの概念でサブクエリを使用できます。以下は例です。 テーブルを作成します。 mysql> create table Last10RecordsDemo -> ( -> id int, -> name varchar(100) -> ); Query OK, 0 rows affected (0.75 sec) テーブルにレコードを挿入します。 mysql> insert into Last10RecordsDemo values(1,John),(