· 9 years ago · Jan 18, 2017, 09:22 AM
1CREATE TABLE IF NOT EXISTS `status`
2(
3 `hosts` text,
4 `numb` text,
5 `region` text,
6 `status` varchar(2) DEFAULT NULL,
7 `t_tim` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
8)
9ENGINE=MyISAM DEFAULT CHARSET=utf8 AVG_ROW_LENGTH=34;
10
11INSERT INTO `status` (`hosts`, `numb`, `region`, `status`, `t_tim`) VALUES
12('SIU02', '234', 'POV', '1', '2017-01-18 03:44:01'),
13('SIU04', '44', 'POV', '1', '2017-01-18 03:44:01'),
14('SIU03', '24234', 'POV', '1', '2017-01-18 03:44:01'),
15('SIU01', '24234', 'POV', '1', '2017-01-18 03:44:01'),
16('SIU02', '24234', 'SZ', '1', '2017-01-18 03:44:01'),
17('SIU01', '22', 'SIB', '1', '2017-01-18 03:44:01'),
18('SIU02', '34', 'SIB', '1', '2017-01-18 03:44:01'),
19('SIU03', '422', 'SIB', '1', '2017-01-18 03:44:01'),
20('SIU04', '23456', 'SIB', '1', '2017-01-18 03:44:01'),
21('SIU05', '46', 'SIB', '1', '2017-01-18 03:44:01'),
22('SIU07', '324234', 'SIB', '2', '2017-01-18 08:45:12'),
23('SU_FTP', '324', 'MSK', '0', '2017-01-18 03:44:01'),
24('SIU01', '34234', 'SZ', '1', '2017-01-18 03:44:01'),
25('SIU08', '23443', 'SIB', '1', '2017-01-18 03:44:01'),
26('SIU04', '3444', 'SZ', '1', '2017-01-18 03:44:01'),
27('SIU03', '1555', 'SZ', '1', '2017-01-18 03:44:01'),
28('SIU05', '1055', 'SZ', '1', '2017-01-18 03:44:01'),
29('S_FTP', '1223', 'SZ', '1', '2017-01-18 03:44:01'),
30('SIU01', '1232333', 'UG', '2', '2017-01-18 08:45:20'),
31('SIU02', '134234', 'UG', '1', '2017-01-18 03:44:01'),
32('SIU03', '155', 'UG', '1', '2017-01-18 03:44:01'),
33('SIU04', '14545', 'UG', '1', '2017-01-18 03:44:01'),
34('S_FTP', '1454', 'UG', '2', '2017-01-18 08:45:23'),
35('S_FTP', '14545', 'POV', '2', '2017-01-18 08:45:06');
36
37region--status--count
38POV----1--------4
39
40SELECT `status`.`region`, `status`.`status`, COUNT(*)
41FROM `status`
42GROUP BY `status`.`region`, `status`.`status`;
43
44SELECT region,status, COUNT(*) FROM `status` WHERE status=1 OR status=2 OR status=3 OR status=0 GROUP BY region