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 8801605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:52:40+00:00 2026-06-14T00:52:40+00:00

My table data: id fieldId Name Text —- —— —– —- 1 101 name1

  • 0

My table data:

id      fieldId  Name   Text
----    ------  -----   ----
1        101    name1   a1
2        102    name2   a2
3        101    name1   a1
4        103    name3   a2
5        102    name2   a3
6        101    name1   c1
7        101    name1   a3
8        102    name2   
9        101    name1   b2
10       103    name3   c1

I need output like

Name    Count(fieldId)  Count_id_text_is_either_a1_or_a2_a3
------      ------        -------
name1   4                   2
name2   3                   2
name3   2                   1
  • Name = I need to group by fieldId.
  • Count(fieldId) = Count each group records.
  • Count_id_text_is_either_a1_or_a2_a3 = This is the column I want the count of records of group only if Text like 'a1-%' or 'a2-%' or 'a3-%'.

Can this be done by single query? If yes the please explain how? If no then what is the most efficient way to do this?

  • 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-14T00:52:42+00:00Added an answer on June 14, 2026 at 12:52 am
    select Name, 
        count(*) as CountAll, 
        count(case when Text like 'a1-%' or Text like 'a2-%' or Text like 'a3-%' then 1 end) as CountA1A2A3
    from MyTable
    group by Name
    

    You could also use a RegEx if you wish.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can i export table data with column name in text file in sql
a simple table contains - id , name , text . I need to
I have a table data with following columns: |-a-|-b-|-text-| |-1-|-1-|-text-| |-1-|-2-|-text-| |-1-|-3-|-text-| |-2-|-1-|-text-| |-2-|-2-|-text-|
I do have a table data as shown below: <td> <label for=title>Title : </label>
When trying Edit Table Data in MySQL Workbench 5.2.37, its in read only mode.
'Names' in table 'Data' type12pen105A type12pen110A type12pen121B Declare @n int; select Names From Data
A site I'm working on takes table data, counts that table data and uses
im trying to import html table data to an excel file and have succeeded
Suppose we have the following table data: ID parent stage submitted 1 1 1
I'm trying to save some lookup table data out to a YAML file so

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.