mysql - 怎么生成這個(gè)sql表?
問題描述
如圖,要生成這個(gè)sql表,從5點(diǎn)開始到23點(diǎn),間隔15分鐘。
怎么生成呢?
問題解答
回答1:用PHP
$start = strtotime(’20140227050000’);$end = strtotime(’20140227230000’);$step = strtotime(’1970-01-01 08:30:00’);$data = array();while (($start+=$step) <= $end) { $data[] = array(’s’=>date(’Y-m-d H:i:s’,($start-strtotime(’1970-01-01 08:15:00’))),’e’=>date(’Y-m-d H:i:s’,$start) );}echo ’<pre>’;var_dump($data);
將data數(shù)據(jù)插入到sql表即可
再來個(gè)MYSQL的
-- 刪除原有表DROP TABLE IF EXISTS `t`;-- 創(chuàng)建數(shù)據(jù)表CREATE TABLE IF NOT EXISTS `t` ( `s` varchar(255), `e` varchar(255));-- 創(chuàng)建存儲create procedure protest()begindeclare s int;declare t int;declare e int;set s=UNIX_TIMESTAMP(’20140227050000’);set t=900;set e=UNIX_TIMESTAMP(’20140227230000’);while s<e doset s=s+t; insert into t(`s`,`e`) values(FROM_UNIXTIME(s),FROM_UNIXTIME(s+t)); set s=s+t;end while;end;-- 調(diào)用存儲call protest();-- 刪除存儲drop procedure protest;回答2:
你是要生成這樣的表結(jié)構(gòu)?還是說這張表已經(jīng)存在了想要插入這樣的表內(nèi)容
相關(guān)文章:
1. mysql - AttributeError: ’module’ object has no attribute ’MatchType’2. angular.js - ng-grid 和tabset一起用時(shí),grid width默認(rèn)特別小3. 請教各位大佬,瀏覽器點(diǎn) 提交實(shí)例為什么沒有反應(yīng)4. javascript - webapp業(yè)務(wù)流程基本一致,多套主題(樣式基本不一樣,交互稍有偏差)管理,并且有不斷有新增主題,該如何設(shè)計(jì)組件化架構(gòu)?5. dockerfile - 為什么docker容器啟動(dòng)不了?6. javascript - 從mysql獲取json數(shù)據(jù),前端怎么處理轉(zhuǎn)換解析json類型7. macos - mac下docker如何設(shè)置代理8. javascript - 我的站點(diǎn)貌似被別人克隆了, google 搜索特定文章,除了域名不一樣,其他的都一樣,如何解決?9. 新手 - Python 爬蟲 問題 求助10. javascript - 學(xué)習(xí)網(wǎng)頁開發(fā),關(guān)于head區(qū)域一段腳本的疑惑
