Jump to content

i need to do 2 sql statements to create a chart


kurky17

Recommended Posts

Hi all,

I have a table like the one below:

tablename: daily_totals

 

packageID total_bytes date
0123 10 2009-01-01
0123 20 2009-01-02
0124 10 2009-01-01
0124 20 2009-01-02
0125 10 2009-01-01
0125 20 2009-01-02

I need to create a chart based on what package ID the user wants to show with the date as the Xaxis and the total_bytes as the Y-axis. 

He can choose one, or many packages.  He also has the option to choose ALL.  Which means, my chart legend can be the one below if he chooses to show everything:

  • Package 0123
  • Package 0124
  • Package 0125
  • All

*The ALL option is simply summing up the total_bytes of all packageIDs in a given date.

My sql query for per package will be something like:

SELECT packageID, total_bytes, date

FROM daily_totals

WHERE packageID = 0123

Result: 

packageID total_bytes date
0123 10 2009-01-01
0123 20 2009-01-02

My sql query for All Packages will be something like:

SELECT sum(total_bytes), date

FROM daily_totals

GROUP BY date

Result:

total_bytes date
30 2009-01-01
60 2009-01-02

No, I can't do a UNION because i don't think i can do away with the packageID field for the first query. 

How can I show these data on a chart?  My chart legend should have packageID 123 and ALL.

Please help me.

 

Thanks,

Michelle

 

Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...