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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:44:49+00:00 2026-05-22T02:44:49+00:00

I need a MySql query to do the following: Select all the items in

  • 0

I need a MySql query to do the following:
Select all the items in a table, group them by a type, order them by count type and also sum all the count.

This is what I’ve done so far:

select type, count(*) as cnt from $tbl_name group by type order by count(*) desc;

This only gives me the count for each group. What should I add so that this code will also show the total count (sum the counts from every group).

  • 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-22T02:44:50+00:00Added an answer on May 22, 2026 at 2:44 am
    select * from (
    select type as type, 
    count(*) as cnt 
    from $tbl_name 
    group by type WITH ROLLUP) as inner_table
    order by cnt desc;
    

    Note that the first row will be the rolled up total sum.

    ROLLUP reference

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

Sidebar

Related Questions

When I run the following query in ruby: Transaction.all(:select => created_at, SUM(amount) amount, :group
I need some help with a group by mysql query clause. Medals Table (this
I've got a MySQL query somewhat like the following: SELECT * FROM products LEFT
Basically I have a mysql query something like the following: mysql_query(SELECT n.title, v.value FROM
I have the following query in mysql 5.1.41: select distinct table_schema from information_schema.tables where
I have the following query: SELECT location, step, COUNT(*), AVG(foo), YEAR(start), MONTH(start), DAY(start) FROM
I need help building a mysql query to select from multiple tables. I have
How do I use the json_encode() function with MySQL query results? Do I need
I need to run a RLIKE query on a database mmoved from MySQL to
I need to store a url in a MySQL table. What's the best practice

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.