473,749 Members | 2,597 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Query to find the difference b/w averages

38 New Member
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 2360
r035198x
13,262 MVP
Why not just compare the values that you have stored in those local string "objects" that you saved them to?
Dec 19 '08 #2
lildiapaz
38 New Member
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 MVP
You convert a string to a number using Integer.parseIn t. You then compare the integers using the normal comparison operators.
Dec 30 '08 #4
lildiapaz
38 New Member
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
lildiapaz
38 New Member
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
4605
by: Sameer | last post by:
I am supplying you with Sample Data:- Initial Classcode SampleSize Average ------- ---------- ------------------------------- ADK SSC 22 3.6800000000000002 ADK TSC 17 2.7599999999999998 ADK TSM 5 3.5499999999999998 ANB FCA 31 3.23 ANB FCB 50 3.0499999999999998 ANB FCC 30 3.0899999999999999
1
6176
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 the one graph. The output was in the order of the months, but after unioning with the averages SQL code, the order is lost. Below is the full sql code that is the data source for the graph: SELECT (Format(.,"mmm"" '""yy")) AS Month,...
0
2295
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 Access2000) I have three tables (that are part of a different program so I can't change their structure). They are Units, Streams, and _Strms. Units contains info about various units. The fields within Units that I am interested in are ID,...
1
8538
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 field to my report (or does this have to be created in the query?) that calculates the average of all the data in the "Time Taken" field. SQL code or some tips would be much appreciated.
3
1500
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 DriversData: RecordID, DriverID, WeekEnding, MondayHoursWorked, TuesdayHoursWorked, etc. I can get a report for a specific person showing the last 17 weeks, and an average hours per week for this. (I used SELECT TOP 17).
14
3496
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. However, the expectation changes - it may be 60% for a while, then change to 50%. Initially, I was averaging the expectation, along with the productivity, but what I'm being asked is to look at the average productivity/performance compared to...
2
1318
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 tbl_LTandWait WHERE (((tbl_LTandWait.EngSN)<>' Median LT' And (tbl_LTandWait.EngSN)<>' Lead Time Goal' And (tbl_LTandWait.EngSN)<>' Avg Lead Time')) GROUP BY tbl_LTandWait.EngModule
2
1958
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 with _myWord: Here is what I am using: select ((avg(abcd_myWord) + avg(other_myWord) +
1
1137
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
8997
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8833
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9568
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9389
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9256
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4709
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4881
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3320
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2794
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.