ここでMYSQL newbを完成させてください。私はこの質問を投稿することはほぼ恥ずかしいんだけど、ここではそれが行く:テーブルMYSQLの行と出力の差を比較する
だから、私は次の表を持っている...
CREATE TABLE IF NOT EXISTS cran_cisco (
id int not null auto_increment,
device_fqdn varchar(250) DEFAULT 0,
device_ip varchar(250) DEFAULT 0,
link_state varchar(250) DEFAULT 0,
line_protocol varchar(250) DEFAULT 0,
description varchar(250) DEFAULT 0,
date timestamp default now(),
PRIMARY KEY(id)
);
そして、私は、以下の情報を追加するために外部スクリプトを作成して、その1日4回になります。
insert into cran_cisco (device_fqdn, device_ip, link_state, line_protocol, description)
values ('test_box_2', '10.10.10.2', 'up', 'up', 'this is a test interface');
insert into cran_cisco (device_fqdn, device_ip, link_state, line_protocol, description)
values ('test_box_2', '10.10.10.2', 'up', 'down', 'this is a test interface');
insert into cran_cisco (device_fqdn, device_ip, link_state, line_protocol, description)
values ('test_box_2', '10.10.10.2', 'up', 'up', 'this is a test interface');
insert into cran_cisco (device_fqdn, device_ip, link_state, line_protocol, description)
values ('test_box_2', '10.10.10.2', 'up', 'down', 'this is a test interface');
insert into cran_cisco (device_fqdn, device_ip, link_state, line_protocol, description)
values ('test_box_2', '10.10.10.2', 'up', 'down', 'this is a test interface');
insert into cran_cisco (device_fqdn, device_ip, link_state, line_protocol, description)
values ('test_box_2', '10.10.10.2', 'up', 'up', 'this is a test interface');
insert into cran_cisco (device_fqdn, device_ip, link_state, line_protocol, description)
values ('test_box_2', '10.10.10.2', 'up', 'up', 'this is a test interface');
insert into cran_cisco (device_fqdn, device_ip, link_state, line_protocol, description)
values ('test_box_2', '10.10.10.2', 'up', 'down', 'this is a test interface');
insert into cran_cisco (device_fqdn, device_ip, link_state, line_protocol, description)
values ('test_box_2', '10.10.10.2', 'up', 'up', 'this is a test interface');
テーブルを次のようになります:
| id | device_fqdn | device_ip | link_state | line_protocol | description | date |
+----+-------------+------------+------------+---------------+--------------------------+---------------------+
| 1 | test_box_2 | 10.10.10.2 | up | down | this is a test interface | 2016-10-07 08:16:42 |
| 2 | test_box_2 | 10.10.10.2 | up | up | this is a test interface | 2016-10-07 08:17:22 |
| 3 | test_box_2 | 10.10.10.2 | up | up | this is a test interface | 2016-10-07 08:23:55 |
| 4 | test_box_2 | 10.10.10.2 | up | down | this is a test interface | 2016-10-07 08:23:55 |
| 5 | test_box_2 | 10.10.10.2 | up | up | this is a test interface | 2016-10-07 08:23:55 |
| 6 | test_box_2 | 10.10.10.2 | up | up | this is a test interface | 2016-10-07 08:23:55 |
| 7 | test_box_2 | 10.10.10.2 | up | down | this is a test interface | 2016-10-07 08:23:55 |
| 8 | test_box_2 | 10.10.10.2 | up | up | this is a test interface | 2016-10-07 08:23:55 |
| 9 | test_box_2 | 10.10.10.2 | up | up | this is a test interface | 2016-10-07 08:23:55 |
| 10 | test_box_2 | 10.10.10.2 | up | down | this is a test interface | 2016-10-07 08:23:55 |
| 11 | test_box_2 | 10.10.10.2 | up | up | this is a test interface | 2016-10-07 08:23:57 |
+----+-------------+------------+------------+---------------+--------------------------+---------------------+
私はラインプロトコルまたはリンクがダウンしたすべての時間を報告するクエリを開発したいと思いますここではそれがどのように見えるかの抜粋です。期待出力は次のようになります。
| id | device_fqdn | device_ip | link_state | line_protocol | description | date |
+----+-------------+------------+------------+---------------+--------------------------+---------------------+
| 1 | test_box_2 | 10.10.10.2 | up | down | this is a test interface | 2016-10-07 08:16:42 |
| 4 | test_box_2 | 10.10.10.2 | up | down | this is a test interface | 2016-10-07 08:23:55 |
| 7 | test_box_2 | 10.10.10.2 | up | down | this is a test interface | 2016-10-07 08:23:55 |
| 10 | test_box_2 | 10.10.10.2 | up | down | this is a test interface | 2016-10-07 08:23:55 |
+----+-------------+------------+------------+---------------+--------------------------+---------------------+
ご協力いただければ幸いです。前もって感謝します。
約束どおり、私の質問に対する答えは以下の通りです。私は別の質問が来ますが、それをすべてbashスクリプトに入れる方法を扱っています。笑
SELECT 'cran_juniper' AS `set`, c.*
FROM cran_juniper c
WHERE ROW(c.device_fqdn, c.device_ip, c.interface, c.admin_state, c.link_state, c.description) NOT IN
(
SELECT device_fqdn, device_ip, interface, admin_state, link_state, description
FROM cran_juniper_baseline
)
UNION ALL
SELECT 'cran_juniper_baseline' AS `set`, b.*
FROM cran_juniper_baseline b
WHERE ROW(b.device_fqdn, b.device_ip, b.interface, b.admin_state, b.link_state, b.description) NOT IN
(
SELECT device_fqdn, device_ip, interface, admin_state, link_state, description
FROM cran_juniper
)
into outfile 'today.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n';
;
私はあなたがそのデバイスの前の行とすべての行を比較し、link_stateおよび/またはline_protocolが正しい、アップからダウンに変更されたかどうか?見てみたいと思いますか – verhie