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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:02:02+00:00 2026-06-14T11:02:02+00:00

In the example table below, I’m trying to figure out a way to sum

  • 0

In the example table below, I’m trying to figure out a way to sum amount over id for all marks where mark ‘C’ doesn’t exist within an id. When mark ‘C’ does exist in an id, I want the sum of amounts over that id, excluding the amount against mark ‘A’. As illustration, my desired output is at the bottom. I’ve considered using partitions and the EXISTS command, but I’m having trouble conceptualizing the solution. If any of you could take a look and point me in the right direction, it would be greatly appreciated 🙂

sample table:

id   mark  amount
------------------
1    A     1
2    A     3
2    B     2
3    A     2
4    A     1
4    B     3
5    A     1
5    C     3
6    A     2
6    C     2

desired output:

id   sum(amount)
-----------------
1    1
2    5
3    2
4    4
5    3
6    2
  • 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-14T11:02:03+00:00Added an answer on June 14, 2026 at 11:02 am
    select 
      id, 
      case 
         when count(case mark when 'C' then 1 else null end) = 0 
         then 
            sum(amount)
         else 
            sum(case when mark <> 'A' then amount else 0 end)
      end
    from sampletable
    group by id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a table t_points in mySql like example in below. Name Surname Point
I have a SQLite table called posts . An example is shown below. I
Given the example table below, how can I retrieve the high and low range
I have three tables kinda like the example below: TABLE CARS carId carName -----
Consider I have a table, like below, that I am trying to populate with
I'm new to the SQL query language and I'm trying to figure out how
for example I have the table below and want to rotate it like the
Consider example table below ProductDetailNo ProductDescription 224 Apples 225 Tomatoes 226 Potatoes How do
What would be the best sql to get data out from the table below
I am trying to parse the table below but unfortunately each of nodes seems

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.