我正在努力进行SQL查询。
我确实需要知道网络,cidr,vrfold(id,名称和主干)和vrfnew(id,name和backbone)。
也许有人可以提供帮助。
networks
+-----------------+---------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+---------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| network | varbinary(16) | NO | | NULL | |
| cidr | int(11) | NO | | NULL | |
| vrfnew_id | int(11) | YES | MUL | NULL | |
| vrfold_id | int(11) | NO | MUL | NULL | |
| vlan | varchar(45) | YES | | NULL | |
+-----------------+---------------+------+-----+---------+----------------+
vrfs
+--------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------+-------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(45) | NO | | NULL | |
| backbones_id | int(11) | NO | MUL | NULL | |
+--------------+-------------+------+-----+---------+----------------+
backbones
+-------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(25) | NO | | NULL | |
+-------+-------------+------+-----+---------+----------------+
答案 0 :(得分:0)
试试这个:
SELECT A.network,
A.cidr,
A.vrfold_id,
B.name as vrfold_name,
C.name as vrfold_backbone_name,
A.vrfnew_id,
D.name as vrfnew_name,
E.name as vrfnew_backbone_name
FROM networks A
JOIN vrfs B on A.vrfold_id = B.id
JOIN backbones C on B.backbones_id = C.id
JOIN vrfs D on A.vrfnew_id = D.id
JOIN backbones E on D.backbones_id = E.id