Skip to content

Show alert component if certain conditions are met #142

Answered by lovasoa
vladosam asked this question in Q&A
Discussion options

You must be logged in to vote

You can add a HAVING clause to the outer query to prevent it from returning a row if you don't have values:

SELECT
    'alert' AS component,
    'Missing value update' AS title,
    string_agg(mac::text, ', ') AS description,
    'alert-circle' AS icon,
    'red' AS color
FROM (
  SELECT mac, MAX(created_at) AS max_created_at
  FROM node
  GROUP BY mac
  HAVING MAX(created_at) < NOW() - INTERVAL '2 minutes'
) AS subquery
HAVING count(*) > 0;

I'm happy to answer your questions here, but when you have more general questions that are related to SQL in general and are not specific to SQLPage, you may receive better answers by asking on stackoverflow. When asking there, you can mention in the …

Replies: 10 comments 13 replies

Comment options

You must be logged in to vote
1 reply
@vladosam
Comment options

Comment options

You must be logged in to vote
3 replies
@lovasoa
Comment options

@vladosam
Comment options

@lovasoa
Comment options

Comment options

You must be logged in to vote
1 reply
@lovasoa
Comment options

Comment options

You must be logged in to vote
1 reply
@lovasoa
Comment options

Comment options

You must be logged in to vote
1 reply
@lovasoa
Comment options

Comment options

You must be logged in to vote
2 replies
@lovasoa
Comment options

@lovasoa
Comment options

Comment options

You must be logged in to vote
1 reply
@lovasoa
Comment options

Comment options

You must be logged in to vote
1 reply
@lovasoa
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@lovasoa
Comment options

Answer selected by vladosam
@vladosam
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants