Question

I am working with a charting program to show monthly inventory totals. So far I only have data for May (the June data will be inserted into the table automatically on June 1st and timestamped).

I am using the below query, and it returns 1 row showing 375 devices for the month of May like this:

devices     created_month
-------     -------------
375         5/1/2012

Is this query set up properly so that on June 1st if I have 380 devices I will receive the following output?

devices     created_month
-------     -------------
375         5/1/2012
380         6/1/2012

I'd just like to confirm that I am interpreting this query properly.

SELECT count(device_type) as devices, description, ip_address, user_tag,                  
  DATE_FORMAT(LAST_UPDATE,"%Y-%m") as created_month 
FROM ahrq_inventory_internal 
GROUP BY created_month
Was it helpful?

Solution

Yes, I believe your code will work correctly.

You have additional columns in the query (description, ip_address, user_tag) and they are not needed.

In fact, having them there will be misleading. Any value in the column will not make sense since those values have no meaning if you group them by month -- unless they all have the same value for every record for the entire month!

So for this reason, I'd recommend changing it to this:

SELECT count(device_type) as devices, 
  DATE_FORMAT(LAST_UPDATE,"%Y-%m") as created_month 
FROM ahrq_inventory_internal 
GROUP BY created_month
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top