Last active
September 3, 2015 13:40
-
-
Save 844196/84ded5338959feed5957 to your computer and use it in GitHub Desktop.
SQL ダミーテーブルの生成からレコード抽出まで http://sqlfiddle.com/#!9/4c9af/12
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CREATE TABLE `users` ( | |
| `id` INTEGER PRIMARY KEY AUTO_INCREMENT, | |
| `section_cd` INTEGER(1), | |
| `username` VARCHAR(255), | |
| `mail_address` VARCHAR(255), | |
| `delete_flg` INTEGER(1), | |
| `created_at` DATETIME | |
| ); | |
| INSERT INTO `users` () VALUES (), (), (), (), (); | |
| INSERT INTO `users` (ID) SELECT 0 FROM `users`; | |
| UPDATE `users` SET | |
| `section_cd` = CEIL(RAND() * 4), | |
| `username` = CONCAT('User', `id`), | |
| `mail_address` = CONCAT(SUBSTRING(MD5(RAND()), 1, 30), '@gmail.com'), | |
| `delete_flg` = RAND(), | |
| `created_at` = ADDTIME( | |
| CONCAT_WS(' ', '2015-09-01' + INTERVAL RAND() * 31 DAY, '00:00:00'), | |
| SEC_TO_TIME(FLOOR(0 + RAND() * 86401)) | |
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| id | section_cd | username | mail_address | delete_flg | created_at | |
|---|---|---|---|---|---|---|
| 1 | 1 | User1 | [email protected] | 0 | September, 30 2015 23:18:55 | |
| 2 | 1 | User2 | [email protected] | 0 | September, 05 2015 07:53:00 | |
| 3 | 2 | User3 | [email protected] | 1 | September, 16 2015 10:27:38 | |
| 4 | 3 | User4 | [email protected] | 0 | September, 29 2015 01:49:58 | |
| 5 | 3 | User5 | [email protected] | 0 | September, 17 2015 17:40:50 | |
| 6 | 1 | User6 | [email protected] | 1 | September, 30 2015 01:27:57 | |
| 7 | 2 | User7 | [email protected] | 0 | September, 22 2015 01:53:18 | |
| 8 | 2 | User8 | [email protected] | 1 | September, 28 2015 05:08:25 | |
| 9 | 2 | User9 | [email protected] | 0 | September, 14 2015 19:17:43 | |
| 10 | 3 | User10 | [email protected] | 0 | September, 25 2015 19:10:51 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SELECT | |
| `id`, `section_cd`, `username`, `mail_address` -- ID、部署コード、ユーザーネーム、メールアドレスを出力 | |
| FROM | |
| `users` | |
| WHERE 1 | |
| AND `delete_flg` = 0 -- 削除フラグの立っていないもの | |
| AND `section_cd` IN (1, 3) -- 部署コードが1, 3のもの | |
| AND `mail_address` LIKE '%10%' -- メールアドレスに'10'が含まれるもの | |
| AND `created_at` >= '2015-09-20' -- 2015/09/20以降に作成されたもの | |
| ORDER BY | |
| `section_cd` DESC -- 部署コード降順 | |
| ; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| id | section_cd | username | mail_address | |
|---|---|---|---|---|
| 10 | 3 | User10 | [email protected] |
Author
844196
commented
Sep 3, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
