記錄一下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/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 在Linux中,目錄結構是怎樣的?Linux
- 磁碟到底是怎樣工作的?一文理解硬碟結構硬碟
- 介面測試返回結構對比實現思路記錄
- Perl語言學習(四)Perl控制結構
- 怎樣寫出優雅的HTML結構?HTML
- 比起 Windows,怎樣解讀 Linux 的檔案系統與目錄結構?WindowsLinux
- 請問一下大家,自動化測試編碼結構是怎麼樣的?
- SQLSERVER 的 nolock 到底是怎樣的無鎖?SQLServer
- 記錄一下MySQL的連線MySql
- 記錄一下svgicon元件的使用SVG元件
- 一般後端返回的資料結構是資料庫中的儲存結構,與前端需要展示的結構不一樣對嗎?後端資料結構資料庫前端
- 記錄一下常用的擴充包
- django的目錄結構Django
- linux的目錄結構Linux
- 怎樣錄屏?好用的錄屏方法分享
- linux檔案系統的目錄結構筆記Linux筆記
- 程式碼目錄結構記錄
- 並查集是一種怎樣的資料結構?並查集資料結構
- SpringBoot中的目錄結構Spring Boot
- MySQL的varchar儲存原理:InnoDB記錄儲存結構MySql
- 同樣網路結構,不一樣的推理速度?--記一次奇怪的踩坑
- perl的logwrapperAPP
- DedeCMS模板目錄的檔案目錄結構
- SQL 如何返回最大值所在的多條記錄SQL
- win10怎樣看歷史記錄_win10檢視歷史記錄的方法Win10
- 記錄一下
- JVM的基本結構和JVM的記憶體結構JVM記憶體
- 簡單瞭解一下pinia的結構
- 單車的重點和坑記錄一下
- 重新記錄一下ArcGisEngine安裝的過程
- 記錄一下 Windows 下搭建 Homestead 的兩大坑Windows
- 記錄常用的一些樣式
- [譯] 怎樣(以及為什麼要)保持你的 Git 提交記錄的整潔Git
- InnoDB記錄儲存結構
- 大廠做系統效能分析的思路到底是怎樣的?
- 常用的HashMap到底是個什麼結構HashMap
- require的到底有沒有返回值?UI
- go專案結構是怎麼樣的?go入門學習Go