By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,610 Members | 2,332 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,610 IT Pros & Developers. It's quick & easy.

calculation percentages using sql command

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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.