enter image description hereI tried to create a SQL query in Microsoft MS by using Pivot that listed people(column1) counts of food and medicine products( so in column 2 should be both types of product for each person) and bought by month ( so next tree columns JAN, Feb, March).
The expected result I am eager to divide the product by 2 types in the “Product” column
At this moment I have this, but this counts only the total number of positions.
select
person,
[January],
[February],
[March]
from
(
select
person,
,
DATENAME(Month, CreationTime) AS [Month],
product
from
report
where
producttype = 'food'
or product = 'medicine'
and year(creationTime) = 2024
) as srs pivot (
count(product) for [Month] in ([January], [February], [March])
) as pvt
I will be appreciate if you can help me to reach my expected result ( please look at pic. )
Iaroslava Garmash is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.