Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7570491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:26:23+00:00 2026-05-30T15:26:23+00:00

Is there any way to have a query return say 8 fields but only

  • 0

Is there any way to have a query return say 8 fields but only group by one field and perform only one aggregate function on another field?
I get an error that suggests that i need to group by by all fields that do not have aggregate functions.

I need to find the number of completed surveys for each month but need to include other information such as session starttime, session status, session id, etc.

When I try to execute this:

SELECT Datepart("m", starttime), 
       COUNT(sessionid), 
       sessionstatus, 
       starttime, 
       endtime, 
       surveyid, 
       surveybook, 
       userdesk 
FROM   survey_sessions 
GROUP  BY Datepart("m", starttime) 

I get the error:
“You tried to execute a query that does not include the specified expression ‘SessionStatus’ as part of an aggregate function”

I do not need any other aggregates and grouping by the remaining fields does not give me ability to get the monthly total.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T15:26:24+00:00Added an answer on May 30, 2026 at 3:26 pm

    If you are using a GROUP BY you ALWAYS have to have all of the fields selected included within the GROUP BY no matter what.

    If you include everything in the group by clause you probably aren’t going to get the results you were expecting because I’m assuming that every row is pretty much unique when grouping on that many columns.

    Assuming you’re using SQL Server could try:

    SELECT Datepart("m", starttime), 
       COUNT(sessionid) OVER(PARTITION BY Datepart("m", starttime)) AS Count, 
       sessionstatus, 
       starttime, 
       endtime, 
       surveyid, 
       surveybook, 
       userdesk 
    FROM   survey_sessions 
    

    This will display the all the information you are looking for with a count of how many occured in the month displayed on each row.

    I’m not 100% sure what you’re trying to accomplish so it’s hard to be more specific.

    EDIT: Adding alternate solution for access.

    If you need it to work in access as well you could try your you could try the following. Replace the ” with a number, date, or string that corresponds with the data-type the first query returns. This will place rows at the bottom of your query with the total for each month.

    SELECT Datepart("m", starttime), 
       0 AS COUNT
       sessionstatus, 
       starttime, 
       endtime, 
       surveyid, 
       surveybook, 
       userdesk 
    FROM   survey_sessions 
    
    UNION ALL 
    
    SELECT Datepart("m", starttime),
       COUNT(sessionid) as Count,
       '',
       '',
       '',
       '',
       '',
       ''
    FROM survey_sessions
    GROUP BY Datepart("m", starttime)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a query which will return one row. Is there any way I
Is there any way to enumerate tables used in mysql query? Lets say I
Is there any way to have something that looks just like a file on
Is there any way to have PHP automatically call a function, before a script
Is there any way to have a Windows batch file directly input SQL statements
Is there any way to have a dropdown in excel that will show a
Is there any way to have the QCompleter to act like an autocomplete for
Is there any way to have a label wordwrap text as needed? I have
Is there any way to have to tabcontrol take the size of the largest
Is there any way to have a default MessageBox.Show() caption? Let says I would

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.