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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:44:56+00:00 2026-05-30T11:44:56+00:00

am stuck in a sql problem. I need something like this M S C

  • 0

am stuck in a sql problem. I need something like this

M S C

1 sent 12
1 checked 15
1 rejected 9
2 sent 20
2 checked 18
3 rejected 10

Where M stands for Month, S for Status and C for Count respectively. What i want to achieve is to group the above example by Month

Wanted:

M S C

1 sent     12
  checked  15
  rejected  9
2 sent     20
  checked  18
  rejected 10

EDIT 1

Right now the sql statement looks like this:

select month, status, sum(hit) as count
from myTable
where dateletter between "date from" and "date to"
group by month,status order by month, status

Edit 2

How would i achieve this too

         1  2

Sent     12 20

Checked  15 18

Rejected 9  10

where 1,2 represent the month values from database.

  • 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-30T11:44:57+00:00Added an answer on May 30, 2026 at 11:44 am
    SELECT month AS M, status AS S, SUM(hit) AS C
    FROM myTable
    WHERE dateletter BETWEEN "date from" AND "date to"
    GROUP BY month, status
    ORDER BY month, status
    

    In the query you cannot group further, you will have to do this in a report. The query is OK and can serve as record source for a report. In such a report, you would insert a group header for each month.


    You could however make a pivot query

    SELECT *
    FROM
      ( SELECT month AS M, status AS S, SUM(hit) AS C
        FROM myTable
        WHERE dateletter BETWEEN "date from" AND "date to"
        GROUP BY month, status
      )
      PIVOT (
        SUM(C)
        FOR S IN ('sent', 'checked', 'rejected')
      );
    

    This would return the status in columns

    M sent checked rejected
    1  12   15       9
    2  20   18      10
    
    • 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 is something like this SELECT t.category, tc.product, tc.sub-product, count(*)
I am stuck figuring out a working SQL Query for the fallowing: I need
I've been stuck with this simple Sql query for last 3 hours and my
I'm stuck in a huge problem where i need to handle huge data. I
In my work, I am stuck with a SQL problem. I have a field
I am badly stuck on this problem and would appreciate any kinds of helps!
Hello stack overflow I need help with this problem. Ok, I have a flat
I'm stuck with a very simple criteria query problem: sess .createCriteria(user.class, user) .user_c.add(Restrictions.eq(user.status, 1))
This is my first question here on stack overflow. i need help on a
I need to select data from two table using a join. This is fairly

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.