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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:39:05+00:00 2026-05-23T02:39:05+00:00

Here is a query that groups transactions by pricepoint on an hourly basis: SELECT

  • 0

Here is a query that groups transactions by pricepoint on an hourly basis:

SELECT hour(Stamp) AS hour, PointID AS pricepoint, count(1) AS counter
FROM Transactions
GROUP BY 1,2;

Sample output:

+------+------------+---------+
| hour | pricepoint | counter |
+------+------------+---------+
|    0 |         19 |       5 |
|    0 |         20 |      14 |
|    1 |         19 |       3 |
|    1 |         20 |      12 |
|    2 |         19 |       2 |
|    2 |         20 |       8 |
|    3 |         19 |       2 |
|    3 |         20 |       4 |
|    4 |         19 |       1 |
|    4 |         20 |       1 |
|    5 |         19 |       4 |
|    5 |         20 |       1 |
|    6 |         20 |       2 |
|    8 |         19 |       1 |
|    8 |         20 |       4 |
|    9 |         19 |       2 |
|    9 |         20 |       5 |
|   10 |         19 |       6 |
|   10 |         20 |       1 |
|   11 |         19 |      10 |
|   11 |         20 |       2 |
|   12 |         19 |      10 |
|   12 |         20 |       3 |
|   13 |         19 |      10 |
|   13 |         20 |      10 |
|   14 |         19 |       8 |
|   14 |         20 |       3 |
|   15 |         19 |       6 |
|   15 |         20 |       8 |
|   16 |         19 |      11 |
|   16 |         20 |      10 |
|   17 |         19 |       7 |
|   17 |         20 |      17 |
|   18 |         19 |       7 |
|   18 |         20 |       9 |
|   19 |         19 |      10 |
|   19 |         20 |      12 |
|   20 |         19 |      17 |
|   20 |         20 |      11 |
|   21 |         19 |      12 |
|   21 |         20 |      29 |
|   22 |         19 |       6 |
|   22 |         20 |      21 |
|   23 |         19 |       9 |
|   23 |         20 |      23 |
+------+------------+---------+

As you can see, some hours have no transactions (e.g 7am), and some hours only have transactions for a single pricepoint (e.g. 6am, only pricepoint 20 but no transactions for pricepoint 19).

I would like to display the results set with “0” when there are no transactions, rather than just not being there as is the case now.

Trying to work with a LEFT OUTER JOIN there. The inHour table contains values 0..23

SELECT H.hour, PointID AS Pricepoint, COALESCE(T.counter, 0) AS Count
FROM inHour H
LEFT OUTER JOIN
(
 SELECT hour(Stamp) AS Hour, PointID, count(1) AS counter
 FROM Transactions
 GROUP BY 1,2
 ) T
ON T.Hour = H.hour;

This produces the following output (truncated for brevity):

|    5 |         19 |     4 |
|    5 |         20 |     1 |
|    6 |         20 |     2 |
|    7 |       NULL |     0 |
|    8 |         19 |     1 |
|    8 |         20 |     4 |

What I would like in fact would be:

|    5 |         19 |     4 |
|    5 |         20 |     1 |
|    6 |         19 |     0 |
|    6 |         20 |     2 |
|    7 |         19 |     0 |
|    7 |         20 |     0 |
|    8 |         19 |     1 |
|    8 |         20 |     4 |

In my desired output, the value “0” is put next to pricepoints that had no transactions during a given hour.

Your suggestions would be welcome! Thanks.

  • 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-23T02:39:06+00:00Added an answer on May 23, 2026 at 2:39 am
    SELECT h.Hour, p.Pricepoint, COUNT(t.*) AS Count
    FROM inHour h,
    (SELECT DISTINCT PointId AS Pricepoint FROM Transactions) p
    LEFT OUTER JOIN Transactions t
    ON h.Hour = hour(t.Stamp) AND p.Pricepoint = t.PointID
    GROUP BY h.Hour, p.Pricepoint
    ORDER BY h.Hour, p.Pricepoint
    

    I don’t have time at the moment to try this, so let me know if it doesn’t work and I’ll try to adjust.

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

Sidebar

Related Questions

Here is the query that I am working on: SELECT `unitid`, `name` FROM apartmentunits
Here's the query: SELECT COUNT(*) AS c, MAX(`followers_count`) AS max_fc, MIN(`followers_count`) AS min_fc, MAX(`following_count`)
Here is my query Select Gender from Table The result pane shows 1 1
Ok, here's a query that I am running right now on a table that
Here is the snapshot of the query that doesn't work since I added the
Here is the issue I am having: I have a large query that needs
Here is a silly question. Lets say I have a query that produces for
How to return a select result with batches through a single query, that should
I have a Linq Group By query that works. Here's the query: Dim query
This is query I have at the moment: SELECT `groups`.`id`, `groups`.`name`, `groups`.`description`, `groups`.`members`, `groups`.`image`,

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.