/build/static/layout/Breadcrumb_cap_w.png

Smart label for machines without a label in a group

We have applied labels indicating locations to the majority of computers in our inventory. All of the location labels are in a label group "Location".

I have a SQL statement that will find machines that don't have a label in the Location group:
SELECT * FROM
(SELECT MACHINE.*, group_concat(distinct LABEL.NAME separator ",") AS LABELS,
group_concat(distinct PARENTLABEL.NAME separator ",") AS PARENTLABELS
FROM ORG1.MACHINE
LEFT JOIN MACHINE_LABEL_JT ON (MACHINE_LABEL_JT.MACHINE_ID = MACHINE.ID)
LEFT JOIN LABEL ON (LABEL.ID = MACHINE_LABEL_JT.LABEL_ID AND LABEL.TYPE <> 'hidden')
LEFT JOIN LABEL_LABEL_JT on LABEL_LABEL_JT.CHILD_LABEL_ID = LABEL.ID
LEFT JOIN LABEL PARENTLABEL on (PARENTLABEL.ID = LABEL_LABEL_JT.LABEL_ID AND LABEL.TYPE <> 'hidden')
GROUP BY MACHINE.ID) as MACHINESWITHLABELS
WHERE PARENTLABELS not like '%Location%'
ORDER BY NAME

This works to create a report that shows all of the machines that don't have a "Location" label applied, but I'd like to have a smart label which would be applied to those machines. If I try using the above code in the smart label it doesn't work. Does anyone have suggestions?

0 Comments   [ + ] Show comments

Answers (1)

Answer Summary:
SELECT *, Unix_timestamp(NOW()) - Unix_timestamp(LAST_SYNC) AS LAST_SYNC_TIME, Unix_timestamp(MACHINE.LAST_SYNC) AS LAST_SYNC_SECONDS FROM ORG1.MACHINE LEFT JOIN KBSYS.KUID_ORGANIZATION ON KUID_ORGANIZATION.KUID = MACHINE.KUID LEFT JOIN KBSYS.SMMP_CONNECTION ON SMMP_CONNECTION.KUID = MACHINE.KUID AND KUID_ORGANIZATION.ORGANIZATION_ID = 1 WHERE MACHINE.ID NOT IN (SELECT M.ID FROM LABEL CHILD, LABEL_LABEL_JT LL, LABEL PARENT, MACHINE M, MACHINE_LABEL_JT ML WHERE CHILD.ID = LL.CHILD_LABEL_ID AND LL.LABEL_ID = PARENT.ID AND M.ID = ML.MACHINE_ID AND ML.LABEL_ID = CHILD.ID AND PARENT. NAME = 'LOCATION')
Posted by: dchristian 12 years ago
Red Belt
3
Does this work?


SELECT *,
Unix_timestamp(NOW()) - Unix_timestamp(LAST_SYNC) AS LAST_SYNC_TIME,
Unix_timestamp(MACHINE.LAST_SYNC) AS LAST_SYNC_SECONDS
FROM ORG1.MACHINE
LEFT JOIN KBSYS.KUID_ORGANIZATION
ON KUID_ORGANIZATION.KUID = MACHINE.KUID
LEFT JOIN KBSYS.SMMP_CONNECTION
ON SMMP_CONNECTION.KUID = MACHINE.KUID
AND KUID_ORGANIZATION.ORGANIZATION_ID = 1
WHERE MACHINE.ID NOT IN (SELECT M.ID
FROM LABEL CHILD,
LABEL_LABEL_JT LL,
LABEL PARENT,
MACHINE M,
MACHINE_LABEL_JT ML
WHERE CHILD.ID = LL.CHILD_LABEL_ID
AND LL.LABEL_ID = PARENT.ID
AND M.ID = ML.MACHINE_ID
AND ML.LABEL_ID = CHILD.ID
AND PARENT. NAME = 'LOCATION')

Comments:

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

Share

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ