473,379 Members | 1,335 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,379 software developers and data experts.

How can I return (x,y) query values to create a graph?

Im trying to build a graph of values from a counterTable. (Eg - get a
list of how many times a page was requested in a week period with each
y value being a day).
If the table looks like this...

counterTable
+-----+------------+
| id | date |
+-----+------------+
| 1 | 2004-08-01 |
| 1 | 2004-08-02 |
| 1 | 2004-08-02 |
| 1 | 2004-08-03 |
| 1 | 2004-08-04 |
| 1 | 2004-08-04 |
| 1 | 2004-08-04 |
| 1 | 2004-08-04 |
| 1 | 2004-08-05 |
| 1 | 2004-08-05 |
| 1 | 2004-08-06 |
| 1 | 2004-08-06 |
| 1 | 2004-08-06 |
| 1 | 2004-08-07 |
+-----+------------+
The graph should look like this...

4 x
3 x x
2 x x x x
1 x x x x x x x
0 1 2 3 4 5 6 7
So far my messy SQL query looks like this...

SELECT count(id) as x, (INTERVAL 1 DAY) as y
FROM counterTable
WHERE id = 1
AND date > 2004-08-01
AND date < 2004-08-07
GROUP BY y

Any suggestions on how I can get the x,y values returned in a single
query? TIA -Nick
Jul 20 '05 #1
3 1882
Nick wrote:
SELECT count(id) as x, (INTERVAL 1 DAY) as y
FROM counterTable
WHERE id = 1
AND date > 2004-08-01
AND date < 2004-08-07
GROUP BY y

Any suggestions on how I can get the x,y values returned in a single
query? TIA -Nick


This seems to work in my test:

select count(c.id) as x, to_days(c.date)-to_days('2004-08-01') as y
from counterTable c
where c.date between '2004-08-01' and '2004-08-07'
group by c.date;

Regards,
Bill K.
Jul 20 '05 #2
You are an SQL god Bill! Thanks once again. -Nick
Jul 20 '05 #3
Hi Nick,

why that complicated?
Isn't it better to have just one row per day? e.g.:

no date
---------------
1 2004-08-01
20 2004-08-02
....

Like that you save some space in the DB and the SELECT Query is a lot
easier.

Of course you have to make sure that you insert the same date only
once and then only use UPDATE Statements for the rest of the day but
this should be easy to achieve.

Of course I know that this doesn't answer your original question but I
just wanted to give you another idea of how to achieve this goal.

HTH,

Andy
nb********@hotmail.com (Nick) wrote in message news:<ce*************************@posting.google.c om>...
You are an SQL god Bill! Thanks once again. -Nick

Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Nick | last post by:
Im trying to build a graph of values from a counterTable. (Eg - get a list of how many times a page was requested in a week period with each y value being a day). If the table looks like...
11
by: Tom Leylan | last post by:
(I posted this in languages.vb also... I can't figure out where things go if you use a little of a lot of things) Hi all... I'm looking for an example (or a pointer to one) related to the...
0
by: Mujdat Pakkan | last post by:
We have an interesting case where we want to use Postgres both as a database and a front end to a proprietary database. For the latter, we wrote functions that access the proprietary database. Then...
1
by: Randy Powell | last post by:
HI folks, I'm a neophyte Access administrator and user. I've got a database working pretty well that I received a lot of help on here. Thanks! I supervise a small children's crisis program and...
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: Santiago Gomez | last post by:
we need a graph that has information from 2 separate tables (max, avg, and min on one table, and actual data on the other). I can join them into 1 query but the resulting query repeats the max min...
0
by: savas_karaduman | last post by:
I am trying to create graph report with using query results. Query result show me `total quantities` for some related `category name`. When i attempt to create a Chart Report with wizard by using...
5
by: mebrabham | last post by:
Hello, I am trying to create a running subtotal in a query and then graph the running subtotal for each city group. The data looks like this in the table (for illustration): My City My...
16
by: nsymiakakis | last post by:
Hi All, First let me start by saying, I absolutely love this site. I have an access database that records are keyed in including a date field. i.e. 3/4/07, 3/20/07, 4/10/07,4/18/07, 5/4/07... and...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.