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?
It is a little hard to follow what your question. I think you want to eliminate all
dataids that have anyusevalues that are NULL or negative. You can do this with ahavingclause:In addition, I removed the
distinctin theselectclause, since it is unnecessary (you have agroup by). I also gave the table a more readable alias,eainstead of the table name.