473,387 Members | 1,561 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Query to find the difference b/w averages

Hi,

I have wrote two queries, one to find the average for one date, and the second query to find the average for another date. And I stored the results of the query to a local string object. Is there anyway to compare the two averages by getting the difference between the two.

example query
Expand|Select|Wrap|Line Numbers
  1.  
  2. String myQuery = "" +
  3.         "select name, age, date, avg(count) from product where date=interval -7 Day + '2001-08-13'  " +
  4.         " group by name "; 
  5.  
Let's say that I get another query for the next 7 days, how do I compare the two averages from the two queries?

Note: Using Mysql 5.0, and JDBC app to connect to DB, table, etc (works fine)
just need help with the query in my program
Thanks,
Dec 18 '08 #1
5 2347
r035198x
13,262 8TB
Why not just compare the values that you have stored in those local string "objects" that you saved them to?
Dec 19 '08 #2
Thanks for the quick response, but how do I accomplish that? Can you provide a code snippet, or refer me to an article?
Dec 29 '08 #3
r035198x
13,262 8TB
You convert a string to a number using Integer.parseInt. You then compare the integers using the normal comparison operators.
Dec 30 '08 #4
Thanks, I was able to make the conversion from string to int. But my next question is how do I write the sql query to query the database to return the results using the new averages in which I converted to integers?


//newdailyCount is a string like "1.2222"
//firstAverage is an int

Expand|Select|Wrap|Line Numbers
  1. firstAverage=Integer.parseInt(newdailyCount);
Here is the query I tried to return the results after I get the avg of the previous seven days, and the next seven days, then I want to subtract the avgs of the two. But the query doesn't work.

Expand|Select|Wrap|Line Numbers
  1. # String myQuery = "" +
  2. #         "select name, age, date, avg(count) from product where newdailyCount=(firstAverage -10) " +
  3. #         " group by name "; 
Thanks,
Dec 30 '08 #5
Can someone provide a code snippet or suggestions for the query above?

thanks,
Jan 12 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Sameer | last post by:
I am supplying you with Sample Data:- Initial Classcode SampleSize Average ------- ---------- ------------------------------- ADK SSC 22 3.6800000000000002 ADK TSC ...
1
by: Jeff Blee | last post by:
I hope someone can help me get this graph outputing in proper order. After help from Tom, I got a graph to display output from the previous 12 months and include the average of that output all in...
0
by: David | last post by:
This might be a report question but I think it is more a query issue than a report. I am a novice at bothAccess reporting and queries and have been struggling to build the following. (Note using...
1
by: Simon Bailey | last post by:
I currently have a query calculating the gap in days between two dates. The fields being "DateLookedAt" and "DateResolved" plus the calculated field "TimeTaken". I am looking to add another...
3
by: Andrew Fox | last post by:
I have been working on this for a while, and unless I have missed a vital part of Access then I think it is very difficult to do. I have a database with two main tables: Drivers: Driver Details...
14
by: Tina | last post by:
My employer tracks productivity/performance of clinicians (how much they bill) each week, its averages for the month, and the 6 months. These averages are compared to their expected productivity....
2
by: Steeler | last post by:
I am getting the averages of a field LT. When I run it in the query designer: SELECT tbl_LTandWait.EngModule, Avg(tbl_LTandWait.LT) AS AvgOfLT, Avg(tbl_LTandWait.LT_Mfg) AS AvgOfLT_Mfg FROM...
2
by: teser3 | last post by:
I would like to know if it is possible to do a pattern match or better way to condense my below query in Access 2003. Basically I need to query the average with all fields in TableOne that end...
1
by: Gadzeus | last post by:
How do I write a query that averages data from weeks 1 through 10? Example: I want to find the average sales for weeks 1 through 10.
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.