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 8931651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:09:36+00:00 2026-06-15T09:09:36+00:00

I have this query that pulls data that I can use for some analysis:

  • 0

I have this query that pulls data that I can use for some analysis:


SELECT   distinct egauge_analyze_2.dataid,     
date_trunc('hour', egauge_analyze_2.timestamp_localtime)::time AS HOUR, 
avg(egauge_analyze_2.use) AS USE   

FROM   dev.egauge_analyze_2

WHERE egauge_analyze_2.timestamp_localtime BETWEEN
       '2012-07-16 00:00:00' AND '2012-08-17 23:59:59' 

AND egauge_analyze_2.use IS NOT NULL

-- AND use > 0

GROUP BY 1,2 
ORDER BY 1,2

When I use it with the above (as-is) it gives me good data and throws out any dataids (and all their data) that have null values anytime, when I add the extra constraint of use > 0, it stops throwing out dataids will null values.

The data consist of dataids (a value for a unique device), a timestamp, and a USE (power draw of that device at that time) – I am trying to get seasonal profiles for the devices, but throw out whole devices that given null or erroneous (negative) data.

I would like it to throw out all dataids (and all their data) for any value of use that is null or <= 0. Ideas?

  • 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-06-15T09:09:37+00:00Added an answer on June 15, 2026 at 9:09 am

    It is a little hard to follow what your question. I think you want to eliminate all dataids that have any use values that are NULL or negative. You can do this with a having clause:

    SELECT ea.dataid,     
           date_trunc('hour', ea.timestamp_localtime)::time AS HOUR, 
           avg(ea.use) AS USE   
    FROM dev.egauge_analyze_2 ea
    WHERE ea.timestamp_localtime BETWEEN '2012-07-16 00:00:00' AND '2012-08-17 23:59:59'
    GROUP BY 1,2
    having sum(case when use is null or use < 0 then 1 else 0 end) > 0
    ORDER BY 1,2
    

    In addition, I removed the distinct in the select clause, since it is unnecessary (you have a group by). I also gave the table a more readable alias, ea instead of the table name.

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

Sidebar

Related Questions

I have this SQL Query that pulls data from 3 tables. I am unable
I have have this query that i want to execute. SELECT warehouse.expiry_date, pharmacy.expiry_date, drugs.active_substance,
So I have this query that works perfectly: SELECT users.*, GROUP_CONCAT(categories.category_name) AS categories FROM
I have this query that returns the results by ordering it by focus.name ASC.
I have this query that, due to the number of records, is taking several
I have this query that inserts rows, using a subquery like so: INSERT INTO
I have this working query that outputs URL and click counts from database. <?php
I have this linq query that works well (although it may be written better,
So I have this awesome MySQL query that's returning me an awesome array >
This query that I have is returning therapists whose 'therapistTable.activated' is equal to false

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.