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

  • Home
  • SEARCH
  • 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 9181733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:23:23+00:00 2026-06-17T18:23:23+00:00

I have SQL like this: SELECT Mid(Note, InStr(Note, device.)- ( InStr(Note, device.)- InStr(Note, pressure

  • 0

I have SQL like this:

SELECT 
Mid(Note, 
  InStr(Note, "device.")-
  (
   InStr(Note, "device.")-
   InStr(Note, "pressure and")
  )
  +13,
  (InStr(Note, "device.") - InStr(Note, "pressure and")) - 14
  )
  AS [Device],
  Count([Device]),
Date_Field & " " & Time_Field AS [DateTime],
EnteredBy
FROM MyLog
WHERE Note LIKE "*removed and*"
GROUP BY [Device]
ORDER BY Date_Field DESC
;

I would like to GROUP BY that custom field [Device] and count how many of each device there are. But the code above gives the error “… not include the specified expression … as part of an aggregate function” for the “… AS [Device]” section.

How can I accomplish this?

Right now the data looks like:

Record1      12/05/12 03:02:12    User2
Record1      12/02/12 01:02:12    User1
Record1      12/01/12 02:02:12    User2
Record2      12/06/12 03:02:12    User2
Record2      12/07/12 03:02:12    User3

But I would like it to look like:

Record1    3
Record2    2

This is the old SQL that works (does not aggregate):

SELECT Mid(Note, 
  InStr(Note, "device.")-
  (
   InStr(Note, "device.")-
   InStr(Note, "pressure and")
  )
  +13,
  (InStr(Note, "device.") - InStr(Note, "pressure and")) - 14
  ) AS Device, Date_Field & " " & Time_Field AS [DateTime], EnteredBy
FROM MyLog
WHERE Note LIKE "*removed and*"
ORDER BY Date_Field DESC;
  • 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-06-17T18:23:24+00:00Added an answer on June 17, 2026 at 6:23 pm

    You cannot refer to the alias device in a GROUP BY in MS Access, but you can create a subquery and refer to the alias from that.

    This runs for me:

    SELECT EnteredBy, Device, Count(Device) As CountDev FROM (
    SELECT 
    Mid(Note,InStr(Note,"device.")-
             (InStr(Note,"device.")-
              InStr(Note,"pressure and"))+13,
        (InStr(Note,"device.")-InStr(Note,"pressure and"))-14) AS Device, 
    MyLog.EnteredBy
    FROM MyLog
    WHERE MyLog.[Note] Like "*removed and*")
    GROUP BY EnteredBy, Device
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an sql query like this: SELECT IF( (SELECT COUNT(*) FROM `test_table2` WHERE
I have a sql like this: SELECT *, count(*) as cc FROM manytomany GROUP
I have a SQL query, looks something like this: select name, count (*) from
I have a sql statement like this (using mysql 5.5.15): select global_id, count(id) as
So I have an SQL statement looks like this SELECT T1.NAME, COUNT(T2.VALUE) AS numInstances
I have a sql like this: SELECT TOP 1 field_name * FROM table_name and
I have a SQL-statement like this: SELECT name FROM users WHERE deleted = 0;
Hi guys I have an SQL query like this: SELECT * FROM PEOPLE P
I have a lot of SQL queries like this: SELECT o.Id, o.attrib1, o.attrib2 FROM
I have a sql query which looks like this - NSString *createSQL = @SELECT

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.