亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊(cè) 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫(kù)
最近訪問(wèn)板塊 發(fā)新帖
查看: 7602 | 回復(fù): 2
打印 上一主題 下一主題

請(qǐng)教下在mysql下怎樣設(shè)計(jì)一個(gè)股票數(shù)據(jù)數(shù)據(jù)庫(kù) [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2011-04-24 21:26 |只看該作者 |倒序?yàn)g覽
玩股票的時(shí)候發(fā)現(xiàn)一個(gè)問(wèn)題,就是股票的只數(shù)太他媽多了!要用眼睛去一個(gè)個(gè)檢索,根本忙不過(guò)來(lái)!
   咱好歹也是個(gè)程序員,想想可以把數(shù)據(jù)導(dǎo)入代碼,讓電腦根據(jù)我設(shè)定的各種條件來(lái)幫我顯示我需要的股票!
   證券公司的股票軟件可以導(dǎo)出txt格式的數(shù)據(jù)文件,但我發(fā)現(xiàn)如果直接用這些txt文件的話,混亂而又難以管理,而且每次要分析的時(shí)候都要去導(dǎo)入一遍這些文件效率很低!于是我想可否用數(shù)據(jù)庫(kù)來(lái)保存我的這些數(shù)據(jù)!
   上周末和這周末,我下了個(gè)mysql玩了一下,了解了一些database和table的概念,還有大致怎樣用select檢索table!
    但我從manual中看到的table都是2維的,比如像我下面建立的這張stock表,這樣如果我要記錄從比如3年的數(shù)據(jù),豈不是要上千張表了?

有沒有辦法建立一個(gè)三維類似的表,比如二維上我只包含code,name,businesstype,time信息,但另外我又能以time維為軸,為表中每個(gè)成員的time項(xiàng)再建立一個(gè)包含price_close  price_open price_high price_low成員的表?
      

mysql> describe stock;
+--------------+-------------+------+-----+---------+-------+
| Field        | Type        | Null | Key | Default | Extra |
+--------------+-------------+------+-----+---------+-------+
| code         | int(11)     | YES  |     | NULL    |       |
| name         | varchar(20) | YES  |     | NULL    |       |
| price_close  | float       | YES  |     | NULL    |       |
| price_open   | float       | YES  |     | NULL    |       |
| price_high   | float       | YES  |     | NULL    |       |
| price_low    | float       | YES  |     | NULL    |       |
| businesstype | varchar(40) | YES  |     | NULL    |       |
| time         | date        | YES  |     | NULL    |       |
+--------------+-------------+------+-----+---------+-------+
8 rows in set (1.23 sec)

mysql> select * from stock;
+--------+----------+-------------+------------+------------+-----------+--------------+------------+
| code   | name     | price_close | price_open | price_high | price_low | businesstype | time       |
+--------+----------+-------------+------------+------------+-----------+--------------+------------+
| 600019 | 寶鋼股份 |        7.32 |       7.37 |       7.42 |      7.28 | 鋼鐵行業(yè)     | 2011-04-22 |
| 600010 | 包鋼股份 |       7.901 |       8.36 |       8.36 |      7.82 | 鋼鐵行業(yè)     | 2011-04-22 |
+--------+----------+-------------+------------+------------+-----------+--------------+------------+
2 rows in set (0.00 sec)

論壇徽章:
27
CU大牛徽章
日期:2013-03-13 15:15:08CU大;照
日期:2013-05-20 10:46:38CU大;照
日期:2013-05-20 10:46:44CU大;照
日期:2013-09-18 15:24:09CU大牛徽章
日期:2013-09-18 15:24:20CU大;照
日期:2013-09-18 15:24:25CU大牛徽章
日期:2013-09-18 15:24:31CU大牛徽章
日期:2013-09-18 15:24:36CU大;照
日期:2013-09-18 15:24:41CU大;照
日期:2013-09-18 15:24:48CU大牛徽章
日期:2013-09-18 15:24:52處女座
日期:2013-09-27 17:45:43
2 [報(bào)告]
發(fā)表于 2011-04-30 19:08 |只看該作者
建立兩張表即可,一張保存股票公司信息,一張是每天的信息表,中間用code_id做外鍵

  1. drop table if exists stock_code;

  2. drop table if exists stock_day;

  3. /*==============================================================*/
  4. /* Table: stock_code                                            */
  5. /*==============================================================*/
  6. create table stock_code
  7. (
  8.    code                 int not null auto_increment,
  9.    name                 varchar(20) not null,
  10.    businesstype         varchar(40) not null,
  11.    primary key (code)
  12. )
  13. comment = "股票公司信息表"
  14. type = InnoDB;

  15. /*==============================================================*/
  16. /* Table: stock_day                                             */
  17. /*==============================================================*/
  18. create table stock_day
  19. (
  20.    id                   int not null auto_increment,
  21.    code_id              int not null,
  22.    price_close          float not null,
  23.    price_open           float not null,
  24.    price_high           float not null,
  25.    price_low            float not null,
  26.    time                 timestamp not null
  27. )
  28. comment = "股票每天表"
  29. type = InnoDB;

  30. alter table stock_day add constraint FK_Reference_1 foreign key (code_id)
  31.       references stock_code (code) on delete restrict on update restrict;

復(fù)制代碼

論壇徽章:
0
3 [報(bào)告]
發(fā)表于 2011-05-04 22:15 |只看該作者
回復(fù) 3# yifangyou


。≈x謝。∵@世界還是好人多!
您需要登錄后才可以回帖 登錄 | 注冊(cè)

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號(hào)-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號(hào):11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國(guó)互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過(guò)ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請(qǐng)注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP