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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:43:46+00:00 2026-06-08T03:43:46+00:00

Good morning, I am unsuccessfully trying to create a report using mysql/php, I would

  • 0

Good morning, I am unsuccessfully trying to create a report using mysql/php, I would like to have rows as columns similar to Access Crosstab or Excel Pivot. I have sales staff & monthly sales which I would like to display across the page with month as column headers.

My query below outputs the data but every salesperson has a row for every month which doesnt read very well,

      Jan | Feb | Mar | April

Sales1
Sales2
Sales3
Sales4

Select
  tblcontacts.ContactFullName,
  Count(tblcases.CaseID) As cases,
  MonthName(tblcases.CaseDate) As Monthly
From
  tblcases Inner Join
  tblcontacts On tblcases.ContactAssignedTo =
  tblcontacts.ContactID
Group By
  tblcontacts.ContactFullName,
  MonthName(tblcases.CaseDate)  
  with rollup

Ant advice or pointers appreciated, I have researched but most of it went right over my head!

Kind regards

  • 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-08T03:43:47+00:00Added an answer on June 8, 2026 at 3:43 am

    What you can do is simply group by each contact and use conditional aggregation to count rows based on each month:

    SELECT
        a.ContactFullName,
        SUM(MONTH(b.CaseDate) = 1) AS Jan,
        SUM(MONTH(b.CaseDate) = 2) AS Feb,
        SUM(MONTH(b.CaseDate) = 3) AS Mar,
        SUM(MONTH(b.CaseDate) = 4) AS Apr,
        SUM(MONTH(b.CaseDate) = 5) AS May,
        SUM(MONTH(b.CaseDate) = 6) AS Jun,
        SUM(MONTH(b.CaseDate) = 7) AS Jul,
        SUM(MONTH(b.CaseDate) = 8) AS Aug,
        SUM(MONTH(b.CaseDate) = 9) AS Sep,
        SUM(MONTH(b.CaseDate) = 10) AS Oct,
        SUM(MONTH(b.CaseDate) = 11) AS Nov,
        SUM(MONTH(b.CaseDate) = 12) AS Dec
    FROM
        tblcontacts a
    INNER JOIN
        tblcases b ON a.ContactID = b.ContactAssignedTo
    GROUP BY
        a.ContactFullName
    

    Edit: As per your comments to this answer: to get a price sum of each month, you can do something like:

    SELECT
        a.ContactFullName,
        SUM(IF(MONTH(b.CaseDate) = 1, b.price, 0)) AS Jan,
        SUM(IF(MONTH(b.CaseDate) = 2, b.price, 0)) AS Feb,
        SUM(IF(MONTH(b.CaseDate) = 3, b.price, 0)) AS Mar,
        SUM(IF(MONTH(b.CaseDate) = 4, b.price, 0)) AS Apr,
        SUM(IF(MONTH(b.CaseDate) = 5, b.price, 0)) AS May,
        SUM(IF(MONTH(b.CaseDate) = 6, b.price, 0)) AS Jun,
        SUM(IF(MONTH(b.CaseDate) = 7, b.price, 0)) AS Jul,
        SUM(IF(MONTH(b.CaseDate) = 8, b.price, 0)) AS Aug,
        SUM(IF(MONTH(b.CaseDate) = 9, b.price, 0)) AS Sep,
        SUM(IF(MONTH(b.CaseDate) = 10, b.price, 0)) AS Oct,
        SUM(IF(MONTH(b.CaseDate) = 11, b.price, 0)) AS Nov,
        SUM(IF(MONTH(b.CaseDate) = 12, b.price, 0)) AS Dec
    FROM
        tblcontacts a
    INNER JOIN
        tblcases b ON a.ContactID = b.ContactAssignedTo
    GROUP BY
        a.ContactFullName
    

    Basically, for each row, if the casedate is in a particular month, pass the value of the price column to the SUM aggregation, otherwise, just pass it 0.

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

Sidebar

Related Questions

Good morning, I have mysql queries where I would like to calculate percentage of
Good morning gang. I have a jQuery Datepicker object that is prepoulated using a
Good morning, I would like the code in my controller to look something like
Good Morning, I have a SharePoint site that I've been trying to fix up
Good Morning everyone, I am using an update command in php to update data
good morning, I was trying the SharedPreferences Class and I have created two classes,
Good morning, I have problem with using MasterPage and jQuery. I using jQuery UI
Good morning, I have a .Net 2.0 runtime DLL that I am trying to
Good morning, I'm trying to install libxml2 with python modules. I have tried the
Good morning\evening everyone! i have a string in a format like 0x0SD30SV8GN48N84GN wich represent

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.