I have the following sql query:
select O.name, O.asset_no, A.name as attr_name, AV.string_value, D.dict_value INTO OUTFILE '/tmp/networkchassis_1503_detailed.csv' FIELDS ENCLOSED BY '"' TERMINATED BY ',' ESCAPED BY '"' LINES TERMINATED BY '\r\n'
FROM Object as O
left join AttributeMap as AM on O.objtype_id = AM.objtype_id
left join Attribute as A on AM.attr_id = A.id
left join AttributeValue as AV on AV.attr_id = AM.attr_id and AV.object_id = O.id
left join Dictionary as D on D.dict_key = AV.uint_value and AM.chapter_id = D.chapter_id
left join Chapter as C on AM.chapter_id = C.id WHERE O.id IN ('5261', '5262', '5263', '5461', '5268', '5271', '22469', '5284', '14418', '5288', '5291', '5292', '5294', '5295', '20629', '20630', '5296', '5297', '5307', '5238', '22425', '22426', '5315', '5316', '22429', '22430', '5317', '22431', '22427', '22428', '5320', '5321', '5325', '5326', '13373', '5329', '14671', '14672', '22432', '22433', '8999', '648', '393', '394', '471', '395', '396', '1688', '1689', '268', '269', '5582', '5583', '5584', '5585', '5586', '5587') AND A.name in ("FQDN", "HW Type") ORDER BY O.name;
This returns two rows, per widet, one with FQDN, and the other for HW Type, like so:
+-----------+----------+-----------+--------------------------------+--------------------------------+
| name | asset_no | attr_name | string_value | dict_value |
+-----------+----------+-----------+--------------------------------+----------------------------------------+
| widget1 | 1026857 | HW Type | NULL | HP |
| widget1 | 1026857 | FQDN | widget1.domain.net | NULL |
I'd like to change the query so that I get one row, with both attributes specified. Something like this...
+-----------+----------+-------------------+----------------+--------------------------------+
| name | asset_no | fqdn | hw_type | string_value | dict_value |
+-----------+----------+-----------+--------------------------------+----------------------------------------+
| widget1 | 1026857 | widget2.domain.net| HP |
Aucun commentaire:
Enregistrer un commentaire