記錄一下perl DBI 的selectall_hashref返回的結構到底怎樣的
源資料:
mysql> select * from perf_status where stat_day > '2008-03-01' and spes_id = 1008 and (ip = '172.24.68.74' or ip = '172.24.68.75') order by ip,stat_day;
+------------+---------+--------------+---------+--------------------+---------+-----------+----------------+-----------+
| stat_day | spes_id | ip | day_max | day_max_time | day_sum | night_max | night_max_time | night_sum |
+------------+---------+--------------+---------+--------------------+---------+-----------+----------------+-----------+
| 2008-03-04 | 1008 | 172.24.68.74 | 16 | #22:00:00 | 160 | 10 | #04:50:00 | 98 |
| 2008-03-05 | 1008 | 172.24.68.74 | 14 | #10:40:00 | 221 | 18 | #08:40:00 | 124 |
| 2008-03-06 | 1008 | 172.24.68.74 | 18 | #09:30:00 | 177 | 11 | #08:45:00 | 102 |
| 2008-03-07 | 1008 | 172.24.68.74 | 11 | #09:30:00 | 89 | 13 | #04:50:00 | 108 |
| 2008-03-08 | 1008 | 172.24.68.74 | 50 | #21:45:00 | 92 | 12 | #07:55:00 | 104 |
| 2008-03-09 | 1008 | 172.24.68.74 | 10 | #22:40:00 | 43 | 11 | #05:00:00 | 128 |
| 2008-03-10 | 1008 | 172.24.68.74 | 15 | #09:25:00 | 175 | 11 | #05:10:00 | 103 |
| 2008-03-11 | 1008 | 172.24.68.74 | 17 | #16:10:00 | 166 | 13 | #08:45:00 | 106 |
| 2008-03-12 | 1008 | 172.24.68.74 | 11 | #22:55:00 | 149 | 10 | #05:00:00 | 90 |
| 2008-03-04 | 1008 | 172.24.68.75 | 23 | #11:20:00 | 412 | 13 | #08:55:00 | 134 |
| 2008-03-05 | 1008 | 172.24.68.75 | 25 | #21:45:00 | 370 | 17 | #08:50:00 | 152 |
| 2008-03-06 | 1008 | 172.24.68.75 | 18 | #15:55:00 | 253 | 14 | #08:20:00 | 151 |
| 2008-03-07 | 1008 | 172.24.68.75 | 15 | #10:35:00 | 175 | 15 | #08:45:00 | 125 |
| 2008-03-08 | 1008 | 172.24.68.75 | 8 | #00:05:00 | 29 | 17 | #05:00:00 | 154 |
| 2008-03-09 | 1008 | 172.24.68.75 | 12 | #18:55:00 | 73 | 23 | #08:25:00 | 164 |
| 2008-03-10 | 1008 | 172.24.68.75 | 16 | #09:15:00 | 297 | 10 | #08:35:00 | 132 |
| 2008-03-11 | 1008 | 172.24.68.75 | 10 | #21:55:00#22:35:00 | 215 | 18 | #05:10:00 | 108 |
| 2008-03-12 | 1008 | 172.24.68.75 | 20 | #11:45:00 | 309 | 13 | #04:55:00 | 112 |
+------------+---------+--------------+---------+--------------------+---------+-----------+----------------+-----------+
18 rows in set (0.19 sec)
perl指令碼:
#! /usr/bin/perl
use lib './';
use DBI;
use Data::Dumper;
use JSON;
my $dsn='dbi:mysql:dbStatus;192.168.182.5';
my $user='dbstatus';
my $pass='*******;
my $schema = DBI->connect($dsn,$user,$pass);
my $sql = qq {
select * from perf_status where stat_day > '2008-03-01' and spes_id = 1008 and (ip = '172.24.68.74' or ip = '172.24.68.75'
) order by ip,stat_day;
};
my $hashref = $schema->selectall_hashref($sql,['ip','stat_day']);
print Data::Dumper->Dumper($hashref);
$schema->disconnect();
Dump結果:
[root@robincui cbs_pre]# ./pf.pl
$VAR1 = 'Data::Dumper';
$VAR2 = {
'172.24.68.74' => {
'2008-03-12' => {
'stat_day' => '2008-03-12',
'ip' => '172.24.68.74',
'day_max' => '11',
'day_sum' => '149',
'night_max_time' => '#05:00:00',
'night_sum' => '90',
'spes_id' => '1008',
'day_max_time' => '#22:55:00',
'night_max' => '10'
},
'2008-03-07' => {
'stat_day' => '2008-03-07',
'ip' => '172.24.68.74',
'day_max' => '11',
'day_sum' => '89',
'night_max_time' => '#04:50:00',
'night_sum' => '108',
'spes_id' => '1008',
'day_max_time' => '#09:30:00',
'night_max' => '13'
},
'2008-03-05' => {
'stat_day' => '2008-03-05',
'ip' => '172.24.68.74',
'day_max' => '14',
'day_sum' => '221',
'night_max_time' => '#08:40:00',
'night_sum' => '124',
'spes_id' => '1008',
'day_max_time' => '#10:40:00',
'night_max' => '18'
},
'2008-03-11' => {
'stat_day' => '2008-03-11',
'ip' => '172.24.68.74',
'day_max' => '17',
'day_sum' => '166',
'night_max_time' => '#08:45:00',
'night_sum' => '106',
'spes_id' => '1008',
'day_max_time' => '#16:10:00',
'night_max' => '13'
},
'2008-03-10' => {
'stat_day' => '2008-03-10',
'ip' => '172.24.68.74',
'day_max' => '15',
'day_sum' => '175',
'night_max_time' => '#05:10:00',
'night_sum' => '103',
'spes_id' => '1008',
'day_max_time' => '#09:25:00',
'night_max' => '11'
},
'2008-03-08' => {
'stat_day' => '2008-03-08',
'ip' => '172.24.68.74',
'day_max' => '50',
'day_sum' => '92',
'night_max_time' => '#07:55:00',
'night_sum' => '104',
'spes_id' => '1008',
'day_max_time' => '#21:45:00',
'night_max' => '12'
},
'2008-03-04' => {
'stat_day' => '2008-03-04',
'ip' => '172.24.68.74',
'day_max' => '16',
'day_sum' => '160',
'night_max_time' => '#04:50:00',
'night_sum' => '98',
'spes_id' => '1008',
'day_max_time' => '#22:00:00',
'night_max' => '10'
},
'2008-03-09' => {
'stat_day' => '2008-03-09',
'ip' => '172.24.68.74',
'day_max' => '10',
'day_sum' => '43',
'night_max_time' => '#05:00:00',
'night_sum' => '128',
'spes_id' => '1008',
'day_max_time' => '#22:40:00',
'night_max' => '11'
},
'2008-03-06' => {
'stat_day' => '2008-03-06',
'ip' => '172.24.68.74',
'day_max' => '18',
'day_sum' => '177',
'night_max_time' => '#08:45:00',
'night_sum' => '102',
'spes_id' => '1008',
'day_max_time' => '#09:30:00',
'night_max' => '11'
}
},
'172.24.68.75' => {
'2008-03-12' => {
'stat_day' => '2008-03-12',
'ip' => '172.24.68.75',
'day_max' => '20',
'day_sum' => '309',
'night_max_time' => '#04:55:00',
'night_sum' => '112',
'spes_id' => '1008',
'day_max_time' => '#11:45:00',
'night_max' => '13'
},
'2008-03-07' => {
'stat_day' => '2008-03-07',
'ip' => '172.24.68.75',
'day_max' => '15',
'day_sum' => '175',
'night_max_time' => '#08:45:00',
'night_sum' => '125',
'spes_id' => '1008',
'day_max_time' => '#10:35:00',
'night_max' => '15'
},
'2008-03-05' => {
'stat_day' => '2008-03-05',
'ip' => '172.24.68.75',
'day_max' => '25',
'day_sum' => '370',
'night_max_time' => '#08:50:00',
'night_sum' => '152',
'spes_id' => '1008',
'day_max_time' => '#21:45:00',
'night_max' => '17'
},
'2008-03-11' => {
'stat_day' => '2008-03-11',
'ip' => '172.24.68.75',
'day_max' => '10',
'day_sum' => '215',
'night_max_time' => '#05:10:00',
'night_sum' => '108',
'spes_id' => '1008',
'day_max_time' => '#21:55:00#22:35:00',
'night_max' => '18'
},
'2008-03-10' => {
'stat_day' => '2008-03-10',
'ip' => '172.24.68.75',
'day_max' => '16',
'day_sum' => '297',
'night_max_time' => '#08:35:00',
'night_sum' => '132',
'spes_id' => '1008',
'day_max_time' => '#09:15:00',
'night_max' => '10'
},
'2008-03-08' => {
'stat_day' => '2008-03-08',
'ip' => '172.24.68.75',
'day_max' => '8',
'day_sum' => '29',
'night_max_time' => '#05:00:00',
'night_sum' => '154',
'spes_id' => '1008',
'day_max_time' => '#00:05:00',
'night_max' => '17'
},
'2008-03-04' => {
'stat_day' => '2008-03-04',
'ip' => '172.24.68.75',
'day_max' => '23',
'day_sum' => '412',
'night_max_time' => '#08:55:00',
'night_sum' => '134',
'spes_id' => '1008',
'day_max_time' => '#11:20:00',
'night_max' => '13'
},
'2008-03-09' => {
'stat_day' => '2008-03-09',
'ip' => '172.24.68.75',
'day_max' => '12',
'day_sum' => '73',
'night_max_time' => '#08:25:00',
'night_sum' => '164',
'spes_id' => '1008',
'day_max_time' => '#18:55:00',
'night_max' => '23'
},
'2008-03-06' => {
'stat_day' => '2008-03-06',
'ip' => '172.24.68.75',
'day_max' => '18',
'day_sum' => '253',
'night_max_time' => '#08:20:00',
&nbs
mysql> select * from perf_status where stat_day > '2008-03-01' and spes_id = 1008 and (ip = '172.24.68.74' or ip = '172.24.68.75') order by ip,stat_day;
+------------+---------+--------------+---------+--------------------+---------+-----------+----------------+-----------+
| stat_day | spes_id | ip | day_max | day_max_time | day_sum | night_max | night_max_time | night_sum |
+------------+---------+--------------+---------+--------------------+---------+-----------+----------------+-----------+
| 2008-03-04 | 1008 | 172.24.68.74 | 16 | #22:00:00 | 160 | 10 | #04:50:00 | 98 |
| 2008-03-05 | 1008 | 172.24.68.74 | 14 | #10:40:00 | 221 | 18 | #08:40:00 | 124 |
| 2008-03-06 | 1008 | 172.24.68.74 | 18 | #09:30:00 | 177 | 11 | #08:45:00 | 102 |
| 2008-03-07 | 1008 | 172.24.68.74 | 11 | #09:30:00 | 89 | 13 | #04:50:00 | 108 |
| 2008-03-08 | 1008 | 172.24.68.74 | 50 | #21:45:00 | 92 | 12 | #07:55:00 | 104 |
| 2008-03-09 | 1008 | 172.24.68.74 | 10 | #22:40:00 | 43 | 11 | #05:00:00 | 128 |
| 2008-03-10 | 1008 | 172.24.68.74 | 15 | #09:25:00 | 175 | 11 | #05:10:00 | 103 |
| 2008-03-11 | 1008 | 172.24.68.74 | 17 | #16:10:00 | 166 | 13 | #08:45:00 | 106 |
| 2008-03-12 | 1008 | 172.24.68.74 | 11 | #22:55:00 | 149 | 10 | #05:00:00 | 90 |
| 2008-03-04 | 1008 | 172.24.68.75 | 23 | #11:20:00 | 412 | 13 | #08:55:00 | 134 |
| 2008-03-05 | 1008 | 172.24.68.75 | 25 | #21:45:00 | 370 | 17 | #08:50:00 | 152 |
| 2008-03-06 | 1008 | 172.24.68.75 | 18 | #15:55:00 | 253 | 14 | #08:20:00 | 151 |
| 2008-03-07 | 1008 | 172.24.68.75 | 15 | #10:35:00 | 175 | 15 | #08:45:00 | 125 |
| 2008-03-08 | 1008 | 172.24.68.75 | 8 | #00:05:00 | 29 | 17 | #05:00:00 | 154 |
| 2008-03-09 | 1008 | 172.24.68.75 | 12 | #18:55:00 | 73 | 23 | #08:25:00 | 164 |
| 2008-03-10 | 1008 | 172.24.68.75 | 16 | #09:15:00 | 297 | 10 | #08:35:00 | 132 |
| 2008-03-11 | 1008 | 172.24.68.75 | 10 | #21:55:00#22:35:00 | 215 | 18 | #05:10:00 | 108 |
| 2008-03-12 | 1008 | 172.24.68.75 | 20 | #11:45:00 | 309 | 13 | #04:55:00 | 112 |
+------------+---------+--------------+---------+--------------------+---------+-----------+----------------+-----------+
18 rows in set (0.19 sec)
perl指令碼:
#! /usr/bin/perl
use lib './';
use DBI;
use Data::Dumper;
use JSON;
my $dsn='dbi:mysql:dbStatus;192.168.182.5';
my $user='dbstatus';
my $pass='*******;
my $schema = DBI->connect($dsn,$user,$pass);
my $sql = qq {
select * from perf_status where stat_day > '2008-03-01' and spes_id = 1008 and (ip = '172.24.68.74' or ip = '172.24.68.75'
) order by ip,stat_day;
};
my $hashref = $schema->selectall_hashref($sql,['ip','stat_day']);
print Data::Dumper->Dumper($hashref);
$schema->disconnect();
Dump結果:
[root@robincui cbs_pre]# ./pf.pl
$VAR1 = 'Data::Dumper';
$VAR2 = {
'172.24.68.74' => {
'2008-03-12' => {
'stat_day' => '2008-03-12',
'ip' => '172.24.68.74',
'day_max' => '11',
'day_sum' => '149',
'night_max_time' => '#05:00:00',
'night_sum' => '90',
'spes_id' => '1008',
'day_max_time' => '#22:55:00',
'night_max' => '10'
},
'2008-03-07' => {
'stat_day' => '2008-03-07',
'ip' => '172.24.68.74',
'day_max' => '11',
'day_sum' => '89',
'night_max_time' => '#04:50:00',
'night_sum' => '108',
'spes_id' => '1008',
'day_max_time' => '#09:30:00',
'night_max' => '13'
},
'2008-03-05' => {
'stat_day' => '2008-03-05',
'ip' => '172.24.68.74',
'day_max' => '14',
'day_sum' => '221',
'night_max_time' => '#08:40:00',
'night_sum' => '124',
'spes_id' => '1008',
'day_max_time' => '#10:40:00',
'night_max' => '18'
},
'2008-03-11' => {
'stat_day' => '2008-03-11',
'ip' => '172.24.68.74',
'day_max' => '17',
'day_sum' => '166',
'night_max_time' => '#08:45:00',
'night_sum' => '106',
'spes_id' => '1008',
'day_max_time' => '#16:10:00',
'night_max' => '13'
},
'2008-03-10' => {
'stat_day' => '2008-03-10',
'ip' => '172.24.68.74',
'day_max' => '15',
'day_sum' => '175',
'night_max_time' => '#05:10:00',
'night_sum' => '103',
'spes_id' => '1008',
'day_max_time' => '#09:25:00',
'night_max' => '11'
},
'2008-03-08' => {
'stat_day' => '2008-03-08',
'ip' => '172.24.68.74',
'day_max' => '50',
'day_sum' => '92',
'night_max_time' => '#07:55:00',
'night_sum' => '104',
'spes_id' => '1008',
'day_max_time' => '#21:45:00',
'night_max' => '12'
},
'2008-03-04' => {
'stat_day' => '2008-03-04',
'ip' => '172.24.68.74',
'day_max' => '16',
'day_sum' => '160',
'night_max_time' => '#04:50:00',
'night_sum' => '98',
'spes_id' => '1008',
'day_max_time' => '#22:00:00',
'night_max' => '10'
},
'2008-03-09' => {
'stat_day' => '2008-03-09',
'ip' => '172.24.68.74',
'day_max' => '10',
'day_sum' => '43',
'night_max_time' => '#05:00:00',
'night_sum' => '128',
'spes_id' => '1008',
'day_max_time' => '#22:40:00',
'night_max' => '11'
},
'2008-03-06' => {
'stat_day' => '2008-03-06',
'ip' => '172.24.68.74',
'day_max' => '18',
'day_sum' => '177',
'night_max_time' => '#08:45:00',
'night_sum' => '102',
'spes_id' => '1008',
'day_max_time' => '#09:30:00',
'night_max' => '11'
}
},
'172.24.68.75' => {
'2008-03-12' => {
'stat_day' => '2008-03-12',
'ip' => '172.24.68.75',
'day_max' => '20',
'day_sum' => '309',
'night_max_time' => '#04:55:00',
'night_sum' => '112',
'spes_id' => '1008',
'day_max_time' => '#11:45:00',
'night_max' => '13'
},
'2008-03-07' => {
'stat_day' => '2008-03-07',
'ip' => '172.24.68.75',
'day_max' => '15',
'day_sum' => '175',
'night_max_time' => '#08:45:00',
'night_sum' => '125',
'spes_id' => '1008',
'day_max_time' => '#10:35:00',
'night_max' => '15'
},
'2008-03-05' => {
'stat_day' => '2008-03-05',
'ip' => '172.24.68.75',
'day_max' => '25',
'day_sum' => '370',
'night_max_time' => '#08:50:00',
'night_sum' => '152',
'spes_id' => '1008',
'day_max_time' => '#21:45:00',
'night_max' => '17'
},
'2008-03-11' => {
'stat_day' => '2008-03-11',
'ip' => '172.24.68.75',
'day_max' => '10',
'day_sum' => '215',
'night_max_time' => '#05:10:00',
'night_sum' => '108',
'spes_id' => '1008',
'day_max_time' => '#21:55:00#22:35:00',
'night_max' => '18'
},
'2008-03-10' => {
'stat_day' => '2008-03-10',
'ip' => '172.24.68.75',
'day_max' => '16',
'day_sum' => '297',
'night_max_time' => '#08:35:00',
'night_sum' => '132',
'spes_id' => '1008',
'day_max_time' => '#09:15:00',
'night_max' => '10'
},
'2008-03-08' => {
'stat_day' => '2008-03-08',
'ip' => '172.24.68.75',
'day_max' => '8',
'day_sum' => '29',
'night_max_time' => '#05:00:00',
'night_sum' => '154',
'spes_id' => '1008',
'day_max_time' => '#00:05:00',
'night_max' => '17'
},
'2008-03-04' => {
'stat_day' => '2008-03-04',
'ip' => '172.24.68.75',
'day_max' => '23',
'day_sum' => '412',
'night_max_time' => '#08:55:00',
'night_sum' => '134',
'spes_id' => '1008',
'day_max_time' => '#11:20:00',
'night_max' => '13'
},
'2008-03-09' => {
'stat_day' => '2008-03-09',
'ip' => '172.24.68.75',
'day_max' => '12',
'day_sum' => '73',
'night_max_time' => '#08:25:00',
'night_sum' => '164',
'spes_id' => '1008',
'day_max_time' => '#18:55:00',
'night_max' => '23'
},
'2008-03-06' => {
'stat_day' => '2008-03-06',
'ip' => '172.24.68.75',
'day_max' => '18',
'day_sum' => '253',
'night_max_time' => '#08:20:00',
&nbs
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/82392/viewspace-211671/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- perl DBI 學習總結
- perl dbi oracleOracle
- 在Linux中,目錄結構是怎樣的?Linux
- perl DBI DBD和java 的JDBC對比學習JavaJDBC
- 磁碟到底是怎樣工作的?一文理解硬碟結構硬碟
- Index掃描生成返回記錄的處理流程到底是什麼Index
- 客戶主記錄的結構
- 10,其他控制結構(perl筆記)筆記
- 介面測試返回結構對比實現思路記錄
- 物料主記錄的資料結構資料結構
- 物料主記錄的組織結構
- 請問一下大家,自動化測試編碼結構是怎麼樣的?
- SQLSERVER 的 nolock 到底是怎樣的無鎖?SQLServer
- perl DBI、DBD-mysql、DBD-Oracle安裝MySqlOracle
- URL的返回方式 —— 三種結構
- 比起 Windows,怎樣解讀 Linux 的檔案系統與目錄結構?WindowsLinux
- 瀏覽器歷史記錄的返回瀏覽器
- 記錄一下MySQL的連線MySql
- Oracle的redo到底記錄了什麼Oracle
- 怎樣錄屏?好用的錄屏方法分享
- 一般後端返回的資料結構是資料庫中的儲存結構,與前端需要展示的結構不一樣對嗎?後端資料結構資料庫前端
- django的目錄結構Django
- Perl語言學習(四)Perl控制結構
- Nginx和Perl的結合Nginx
- Program perl 資料結構資料結構
- 並查集是一種怎樣的資料結構?並查集資料結構
- (轉)怎樣才能dump資料庫的內部結構?資料庫
- 程式碼目錄結構記錄
- 某系統架構方案,記錄一下,方便以後的學習!架構
- DBI 資料庫模組剖析:Perl DBI 資料庫通訊模組規範,工作原理和例項資料庫
- 創業公司到底需要怎樣的產品管理流程?創業
- linux的目錄結構Linux
- Laravel的目錄結構分析Laravel
- 記錄一下
- win10怎樣看歷史記錄_win10檢視歷史記錄的方法Win10
- 大廠做系統效能分析的思路到底是怎樣的?
- 同樣網路結構,不一樣的推理速度?--記一次奇怪的踩坑
- linux檔案系統的目錄結構筆記Linux筆記