467,882 Members | 1,203 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,882 developers. It's quick & easy.

calculation percentages using sql command

Hi

I have a table with the following attributes: Timestamp and a value.

I would like to calculate the percentage of how many values occuring
above a figurative threshold value between the hours of 6 and 10 AM?

Is there a function available for doing this in a sql statement?

Thanks
Mahesh

Apr 27 '06 #1
  • viewed: 4559
Share:
3 Replies
Mahesh S wrote:
Hi

I have a table with the following attributes: Timestamp and a value.

I would like to calculate the percentage of how many values occuring
above a figurative threshold value between the hours of 6 and 10 AM?

Is there a function available for doing this in a sql statement?

SELECT (SUM(val) * 100)/COUNT(1) FROM T WHERE stamp BETWEEN ? AND ?

Not sure where the problem lies....

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Apr 27 '06 #2
well, i think i ahvent explained clearly..

consider this table

timestamp value
2005/07/08 6
2005/07/09 7
2005/07/10 8
2005/07/11 6

i would like to calculate the percentage of the a value occuring
between 5 and 7 between two dates?

does that make sense?

cheers

Apr 27 '06 #3
Mahesh S wrote:
well, i think i ahvent explained clearly..

consider this table

timestamp value
2005/07/08 6
2005/07/09 7
2005/07/10 8
2005/07/11 6

i would like to calculate the percentage of the a value occuring
between 5 and 7 between two dates?

SELECT SUM(CASE WHEN value BETWEEN 5 AND 7 THEN 1.0 END)/ COUNT(1)
FROM T WHERE timestamp BETWEEN ? AND ?

That ought to do it.

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Apr 27 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by michael | last post: by
reply views Thread by gavo | last post: by
26 posts views Thread by Mike Barnard | last post: by
5 posts views Thread by Chris H | last post: by
reply views Thread by MrMoon | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.