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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:30:59+00:00 2026-05-23T05:30:59+00:00

I have a column inside my table: tbl_customers that distinguishes a customer record as

  • 0

I have a column inside my table: tbl_customers that distinguishes a customer record as either a LEAD or a CUS.

The column is simply: recordtype, with is a char(1). I populate it with either C, or L.
Obviously C = customer, while L = lead.

I want to run a query that groups by the day the record was created, so I have a column called: datecreated.

Here’s where I get confused with the grouping.

I want to display a result (in one query) the COUNT of customers and the COUNT of leads for a particular day, or date range. I’m successful with only pulling the number for either recordtype:C or recordtype:L , but that takes 2 queries.

Here’s what I have so far:

  SELECT COUNT(customerid) AS `count`, datecreated 
    FROM `tbl_customers` 
   WHERE `datecreated` BETWEEN '$startdate."' AND '".$enddate."' 
     AND `recordtype` = 'C' 
GROUP BY `datecreated` ASC

As expected, this displays 2 columns (the count of customer records and the datecreated).

Is there a way to display both in one query, while still grouping by the datecreated column?

  • 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-23T05:31:00+00:00Added an answer on May 23, 2026 at 5:31 am
    SELECT COUNT(customerid) AS `count`,
        datecreated,
        SUM(`recordtype` = 'C') AS CountOfC,
        SUM(`recordtype` = 'L') AS CountOfL
    FROM `tbl_customers` 
    WHERE `datecreated` BETWEEN '$startdate."' AND '".$enddate."' 
    GROUP BY `datecreated` ASC
    

    See Is it possible to count two columns in the same query

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

Sidebar

Related Questions

I have deleted a column inside a table that is used to populate a
I have a form with the fields inside table cells. On the last column
How to filter DataView/DataTable by time? I have a table with datetime column inside
I have a table inside a form that looks as follows: <td><input type=text name=code[0]
I have a table items and an item_name column inside of it, and I
I have a table inside a couple of nested divs. One column holds an
I have a page that displays a gridview of products. Inside this table is
I have the create inside the table/list that Grails provides. Here is a pictures
I have a table inside a form. It has two columns, the first one
i have to show 3 columns in List view. I tried having table inside

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.