Avatar of Aiysha
Aiysha
Flag for United States of America asked on

group by month and year

How can I group the following by month and day. I can make it work by months but this groups month in all the years in one record.

SELECT SWD_SCADA_Daily.[Well Name], Sum(SWD_SCADA_Daily.[Water Injection (bbl/day)]) AS CumInjection, Avg(SWD_SCADA_Daily.[Injection Pressure (Psi)]) AS AverageDischargePressure, Avg(SWD_SCADA_Daily.[WHP (Psi)]) AS AverageWHP, MONTH(SWD_SCADA_Daily.[Time/Date]) INTO SWD_SCADA_MONTHLY
FROM SWD_SCADA_Daily
GROUP BY SWD_SCADA_Daily.[Well Name], MONTH(SWD_SCADA_Daily.[Time/Date]);

Thank you.
Microsoft AccessSQL

Avatar of undefined
Last Comment
Paul Cook-Giles

8/22/2022 - Mon
Tomas Helgi Johannsson

Hi,

Move the MONTH(SWD_SCADA_Daily.[Time/Date] colum as the second column in the select.

Regards,
  Tomas Helgi
Scott Pletcher

n/a
Aiysha

ASKER
I want to group month and year. Not just the month.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Scott Pletcher

n/a
Aiysha

ASKER
Undefined function 'CONVERT'  in expression.
Scott Pletcher

SORRY, I was thinking SQL Server, didn't see the Access tag.  I'll remove that and let someone who knows Access comment.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Aiysha

ASKER
I know i have to use format but just struggling with complete query setup
Paul Cook-Giles

Add a new column:  Year(SWD_SCADA_Daily.[Time/Date])   (think you'll need to add it to the group by as well).

If you want both year and month in the same column, use MONTH(SWD_SCADA_Daily.[Time/Date]) & " " &  Year(SWD_SCADA_Daily.[Time/Date])
Aiysha

ASKER
I think this should work but I get type mismatch error

SELECT SWD_SCADA_Daily.[Well Name], Sum(SWD_SCADA_Daily.[Water Injection (bbl/day)]) AS CumInjection, Avg(SWD_SCADA_Daily.[Injection Pressure (Psi)]) AS AverageDischargePressure, Avg(SWD_SCADA_Daily.[WHP (Psi)]) AS AverageWHP,

Format([Time/Date],"mmm","yyyy") AS Expr1

INTO SWD_SCADA_MONTHLY
FROM SWD_SCADA_Daily
GROUP BY SWD_SCADA_Daily.[Well Name],

Format([Time/Date],"mmm","yyyy");
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
ASKER CERTIFIED SOLUTION
Paul Cook-Giles

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Aiysha

ASKER
Thank you so much Paul !!
Paul Cook-Giles

of course!  :)