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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:47:50+00:00 2026-06-14T04:47:50+00:00

Suppose I’ve got the following table: time_recorded | room | num_occupied ———————————————- 2012-11-05 00:00:00

  • 0

Suppose I’ve got the following table:

 time_recorded        |   room   | num_occupied
 ----------------------------------------------
 2012-11-05 00:00:00       a          10
 2012-11-05 00:00:00       b          20
 2012-11-05 00:00:00       c          30
 2012-11-05 00:00:00       d          40

 2012-11-05 00:30:00       a          100
 2012-11-05 00:30:00       b          200
 2012-11-05 00:30:00       c          300
 2012-11-05 00:30:00       d          400
                     ...

I need to group the rows when rooms = ‘b’ and ‘c’, so that the resulting output would be

 time_recorded        |   room   | num_occupied
 ----------------------------------------------
 2012-11-05 00:00:00       a          10
 2012-11-05 00:00:00       bc       (20+30)
 2012-11-05 00:00:00       d          40

 2012-11-05 00:30:00       a          100
 2012-11-05 00:30:00       bc      (200+300)
 2012-11-05 00:30:00       d          400
                     ...

I tried the following query, suggested by juergen d:

SELECT 
    *
FROM 
    usage
WHERE 
    DATE(time_recorded) = '2012-11-05'
    GROUP BY CASE WHEN room IN ('b', 'c') THEN 'bc' ELSE room END;

For some reason I get the following returned:

 time_recorded        |   room   | num_occupied
 ----------------------------------------------
 2012-11-05 00:00:00       a          10
 2012-11-05 00:00:00       b          20

What am I doing wrong?

Thank you in advance!

  • 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-14T04:47:51+00:00Added an answer on June 14, 2026 at 4:47 am

    You are grouping by a computed value but not displaying that value.

    You need to place the CASE expression in the SELECT clause too, along with a computed field to show the value of num_occupied. Something like this:

    SELECT 
       time_recorded, CASE WHEN room IN ('b', 'c') THEN 'bc' ELSE room END, 
        SUM(num_occupied)
    FROM 
       usage
    WHERE 
        DATE(time_recorded) = '2012-11-05'
       GROUP BY 1, 2;
    

    (edited per comment)

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

Sidebar

Related Questions

Suppose I have the following table: PERSON : ID INT NAME STRING LASTNAME STRING
Suppose I have two tables, - emp(empId number(1),empName varchar2(50)) and - manager(manId number(5),managerName varchar2(100))
Suppose a file saved on the disk: HTTP/1.1 200 OK Date: Thu, 28 Jun
Suppose I have a base class as following: class User: user_types = [] def
Suppose I have the following code in bash: #!/bin/bash bad_fruit=( apple banana kiwi )
Suppose we have the following: data Foo x from_list :: [x] -> Foo x
Suppose a mysql 5.5 server uses the following configuration for storing innodb data innodb_data_file_path
suppose I have the following serial C: int add(int* a, int* b, int n)
Suppose I have the following two tables: STUDENT studentid lastname firstname 1 Smith John
Suppose I have a table like: Tab(MyDate datetime null, MyIs bit null, ...) Then

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.