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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:22:59+00:00 2026-06-13T15:22:59+00:00

Lets say I have such a table: id|time|operation 1 2 read 2 5 write

  • 0

Lets say I have such a table:

id|time|operation
1  2      read
2  5      write
3  3      read
4  7      read
5  2      save
6  1      open

and now I would like to do two things:

  1. Divide all these records into two groups:
    1) all rows where operation equals to “read”
    2) all other rows.
  2. Sum the time in each group.

So that my query would result only into two rows.

What I got so far is:

select 
 sum(time) as total_time,
 operation
group by
 operation
;

Although that gives me many groups, depending on the number of distinct operations.

How I could group them only into two categories?

Cheers!

  • 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-13T15:23:00+00:00Added an answer on June 13, 2026 at 3:23 pm

    group by can take arbitrary clauses, so

    GROUP BY (operation = 'read')
    

    will work. Essentially you’d be grouping on the boolean result of the comparison, not the value of the operation field, so any record which is “read” will be group 1, and any non-read will be group 0.

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

Sidebar

Related Questions

Lets say I have a table with columns such as: ID Name City State
Let's say I have such XML structure: <table> <tr> <td>&nbsp;</td> </tr> </table> How would
Lets say a have a string such as this one: string txt = Lore
Lets say we have a table here, populated with the following data: acc_id1 acc_id2
I have a table chart. Lets say 5 by 5. I run a loop
For examples sake, lets say I have a table containing these columns ID (primary
Lets say UserA and UserB both have an application open and are working with
Let's say I have a table such as: D_ID C_ID B_ID A_ID 1D 1C
Lets say I have a table called ABC in a MS-Access Database. There are
Let's say I have such a table (ordered by date): id | name |

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.