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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:40:05+00:00 2026-06-17T23:40:05+00:00

Right now, I have a multiple select subquery that is grabbing data based on

  • 0

Right now, I have a multiple select subquery that is grabbing data based on hour of the day that’s a count. What I want to do now, is to introduce another table into that query, and count based on an id as well as the datetime in the original table.

What I have right now is:

select
(
select     count(a_date)
from     t1
where     d_date
     between     '2013-01-07 00:00:00' and '2013-01-07 00:59:59'
) AS     '00:00 to 00:59',
(
select     count(a_date)
from     t1
where     d_date
     between     '2013-01-07 01:00:00' and '2013-01-07 01:59:59'
) AS     '01:00 to 01:59'

and so on, till the end of the day.

I have another query that’s giving me the count based on the id and datetime, but there’s only two columns, one which is showing the c_name and the other showing the count for the hour.

Ex.

select  t2.c_name, count(t1.a_date)
from    t2 join t1
on t2.t1_key = t1.t2_key
where   t1.d_date
    between '2013-01-07 00:00:00' and '2013-01-07 00:59:59'
group by    t2.c_id

Basically, I’d like to combine these two queries into one that can show the c_name and all of the hours of the day.

Any suggestions?

  • 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-17T23:40:06+00:00Added an answer on June 17, 2026 at 11:40 pm

    I would look into using the CASE statement.

    Try something like this (adding your additional 23 columns):

    select  c_name, 
       SUM(case when HOUR(d_date) = 0 then 1 else 0 end) '00:00 to 00:59',
       SUM(case when HOUR(d_date) = 1 then 1 else 0 end) '01:00 to 01:59'
    from   t2
        join t1 on t2.t1_key = t1.t2_key 
    group by c_name
    

    And here is the SQL Fiddle.

    You just need to add your WHERE criteria for d_date — something like:

    where  d_date between '2013-01-07 00:00:00' and '2013-01-07 23:59:59'
    

    or

    where  Date(d_date) = '2013-01-07'
    

    Good luck!

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

Sidebar

Related Questions

I have a select field, with the multiple tag. Right now, the field has
Good day! I right now have a function the drags an element from a
Right now I have a script that will get the last five files in
Right now I have a function, in a class that is used to listen
Right now I have a link that causes a hidden div to appear when
Right now I have a foreach loop that grabs the first link with an
Right now I have a PHP file that does a MYSQL query and then
i have two select box, now what i want is i want to move
I currently have a method right now that looks like the following: public void
I have a view which returns quite a lot of data. Right now, the

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.