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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:15:21+00:00 2026-06-09T01:15:21+00:00

I think it will be easiest to start with the table I have and

  • 0

I think it will be easiest to start with the table I have and the result I am aiming for.

Name | Date
A    | 03/01/2012
A    | 03/01/2012
B    | 02/01/2012
A    | 02/01/2012
B    | 02/01/2012
A    | 02/01/2012
B    | 01/01/2012
B    | 01/01/2012
A    | 01/01/2012

I want the result of my query to be:

Name | 01/01/2012 | 02/01/2012 | 03/01/2012
A    |     1      |     2      |     2
B    |     2      |     2      |     0

So basically I want to count the number of rows that have the same date, but for each individual name. So a simple group by of dates won’t do because it would merge the names together. And then I want to output a table that shows the counts for each individual date using php.

I’ve seen answers suggest something like this:

SELECT
  NAME,
  SUM(CASE WHEN GRADE = 1 THEN 1 ELSE 0 END) AS GRADE1,
  SUM(CASE WHEN GRADE = 2 THEN 1 ELSE 0 END) AS GRADE2,
  SUM(CASE WHEN GRADE = 3 THEN 1 ELSE 0 END) AS GRADE3
FROM Rodzaj
GROUP BY NAME

so I imagine there would be a way for me to tweak that but I was wondering if there is another way, or is that the most efficient?
I was perhaps thinking if the while loop were to output just one specific name and date each time along with the count, so the first result would be A,01/01/2012,1 then the next A,02/01/2012,2 – A,03/01/2012,3 – B,01/01/2012,2 etc. then perhaps that would be doable through a different technique but not sure if something like that is possible and if it would be efficient.

So I’m basically looking to see if anyone has any ideas that are a bit outside the box for this and how they would compare.

I hope I explained everything well enough and thanks in advance for any help.

  • 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-09T01:15:23+00:00Added an answer on June 9, 2026 at 1:15 am

    You have to include two columns in your GROUP BY:

    SELECT   name, COUNT(*) AS count
    FROM     your_table
    GROUP BY name, date
    

    This will get the counts of each name -> date combination in row-format. Since you also wanted to include a 0 count if the name didn’t have any rows on a certain date, you can use:

    SELECT     a.name,
               b.date,
               COUNT(c.name) AS date_count
    FROM       (SELECT DISTINCT name FROM your_table) a
    CROSS JOIN (SELECT DISTINCT date FROM your_table) b
    LEFT JOIN  your_table c ON a.name = c.name AND 
                               b.date = c.date
    GROUP BY   a.name, 
               b.date
    

    SQLFiddle Demo

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

Sidebar

Related Questions

I will start by saying that I don't think what I want can be
What I can think of is: Algo: Have a hash table which will store
I think the easiest way to explain this is by example. I have a
I have an XML with following structure: <table name=tblsiccodes> <row> <sSICCode>0888</sSICCode> </row> <row> <sSICCode>0900</sSICCode>
I looked at django-celery tutorial and I think it will really help me running
Do you think that C# will support something like ??= operator? Instead of this:
If I offload verification to a remote server, I think the process will be
I think even if we will not need interoperability between applications, and even we
I think I probably know that the most common suggestion will be change the
Possible Duplicate: Will XPath 2.0 and/or XSLT 2.0 be implemented in PHP? I think

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.