Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 320113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:43:25+00:00 2026-05-12T08:43:25+00:00

We use a monitoring solution (zabbix). It stores trends data (MySQL 5.X) using a

  • 0

We use a monitoring solution (zabbix). It stores trends data (MySQL 5.X) using a table called trends_uint with the following structure (simplified):

itemid    clock        value_avg
1         1238774400   100
1         1250773900   70
1         1250773200   50

The clock field stores datetime values using Unix time.

I’m trying to extract a report to see the consumption of a monitored item. I thought doing this by selecting the oldest record and the newest record. I achieved it doing the following:

SELECT
(SELECT t.clock FROM trends_uint t WHERE t.itemid = 1 AND t.clock IN (SELECT MIN(t.clock) FROM trends_uint t WHERE t.itemid = 1)) AS minClock,
(SELECT t.value_avg FROM trends_uint t WHERE t.itemid = 1 AND t.clock IN (SELECT MIN(t.clock) FROM trends_uint t WHERE t.itemid = 1)) AS minValueAvg,
(SELECT t.clock FROM trends_uint t WHERE t.itemid = 1 AND t.clock IN (SELECT MAX(t.clock) FROM trends_uint t WHERE t.itemid = 1)) AS maxClock,
(SELECT t.value_avg FROM trends_uint t WHERE t.itemid = 1 AND t.clock IN (SELECT MAX(t.clock) FROM trends_uint t WHERE t.itemid = 1)) AS maxValueAvg,
(SELECT maxClock - minClock) AS timeGap,
(SELECT minValueAvg - maxValueAvg) AS valueGap,
(SELECT timeGap/86400) AS daysGap,
(SELECT valueGap/daysGap/1024/1024) AS consumeMB

My problem is that I have lot’s servers from which I want to calculate the consumption. I don’t want to change the query for which one (changing the itemid).

The system has another table (items) from which I could extract the items that I need to put into the report. Something like SELECT itemid FROM items WHERE ...

So this is my question: instead of using a hardcoded itemid, is it possible to make it “dynamic”, for instance using the returned codes from another query (ex.: SELECT ... FROM ... WHERE itemid IN (SELECT itemid FROM items WHERE ...)?

TIA,

Bob

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T08:43:25+00:00Added an answer on May 12, 2026 at 8:43 am

    It looks like what you want is to use either your programming language’s or MySQL user-defined variables to store the ID you selected once and reuse it.

    I’m assuming you’re using some sort of a language, say PHP, to wrap around these calls.

    You can then:

    • do a SELECT on the itemid, save it as $itemid, and then pass in to your SELECT or
    • use MySQL user-defined variables and save the itemid, with something like

      SET @itemid=SELECT itemid FROM trends_uint WHERE ….

      SELECT …. WHERE t.itemid = @itemid ….

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Our team now uses zabbix for monitoring and alert. In addition, we use fluent
I need to develop a real-time monitoring solution. there is a data source that
Using Observer pattern. I have a class, called Monitor for example, that is monitoring
Which one to use for process monitoring and why?
I am unsure about which monitoring framework to use. Currently I am looking at
use Text::Table; my $tb = Text::Table->new(Planet,Radius\nkm,Density\ng/cm^3); $tb->load( [ Mercury,2360,3.7], [ Mercury,2360,3.7], [ Mercury,2360,3.7], );
I am using VS2005 C# .NET 2.0 I am new to the use of
I use JavaMelody tool to monitoring my application, but the available timeline settings aren't
I'm evaluating Hazelcast as a distributed data grid solution for an application I'm working
I am trying to use monitoring regions to track if users have visited landmarks.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.