开发者

Combining all dates, and data, within a month!

I am trying to combine all days of each month into a date.

My query as off now:

SELECT inventory_items.acquired_at AS Date_Acquired, products.name AS products_name, SUM(inventory_items.primary_quantity) AS inventory_items_primary_quantity FROM inventory_items inventory_items INNER JOIN customers customers ON inventory_items.source_id = customers.id INNER JOIN products products ON inventory_items.product_id = products.id GROUP BY MONTH(Date开发者_Go百科_Acquired), products_name ORDER BY MONTH(Date_Acquired)

I have a general idea of what to do, but not really sure how to implement it.


As I understand you and your Date_Acquired is an instance of sql Date type you can gat day of months as pasting below code inside a textfield

(new SimpleDateFormat("d")).format(new java.util.Date()) 

which suppose to give you numbers like 1,2,3,...18,19...

Extra:

(new SimpleDateFormat("M")).format(new java.util.Date()) for month

(new SimpleDateFormat("yyyy")).format(new java.util.Date()) for year

(new SimpleDateFormat("d")).format(new java.util.Date())+" - "
+(new SimpleDateFormat("M")).format(new java.util.Date()) for getting a value like 28 - 01 


What database? A typical SQL database result can only contain one data value per field. So you will not be able to retrieve all the products.name values in one result grouped by the month. If you retrieve all the results under a specified month you can aggregate them later on.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜