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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:42:49+00:00 2026-05-30T18:42:49+00:00

I think my question will be understood better by providing the following example: i

  • 0

I think my question will be understood better by providing the following example:

i have a table with following data:

orderid  Price username paymentstatus
1        10    john     unpaid
2        10    john     unpaid
4        10    john     unpaid
5        10    john     unpaid
6        10    sam      unpaid
7        10    john     unpaid
8        10    john     paid

I want to find all orders of (username) john where paymentstatus is “unpaid” and price total is <= 20

So the result should show following 2 lines (as order total is $20 and payment status is unpaid and username is john)

EXPECTED RESULT:
==
orderid  Price username paymentstatus
1        10    john     unpaid  
2        10    john     unpaid

==  

I hope you got my point/question?

Please help.. 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-30T18:42:50+00:00Added an answer on May 30, 2026 at 6:42 pm

    Almost EXACT same question answered here. The premise is you would need another column to act as a running total for the customer in question…

    I created table and simulated data exactly like your results and came up with YOUR exact results… The issue was somehow MySQL was applying the criteria TWICE per row and didn’t understand how or why… I STRONGLY suspect its a bug, but can’t describe it. Anyhow, I DO have a fix that forces an inner “PreQuery” as the basis, and return ALL records from that with the @SQLVars and then apply a WHERE clause from that…

    select properSummed.*
       from 
          ( select
                  o.orderid, 
                  o.price, 
                  @RunningTotal := @RunningTotal + o.price as UnpaidSoFar
               from
                  orders o, 
                  (select @RunningTotal := 0 ) sqlvars
               where o.ownerid = 1
                 and o.paymentstatus = 'unpaid' ) properSummed
        where 
           properSummed.UnpaidSoFar <= 50
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am learning LINQ and have a very simple question that I think will
I will preface this question by saying, I do not think it is solvable.
I think the question says it all. I have several monthly processes in stored
I think the question says it all. I'm new to Eclipse plugin development, so
I think the question is pretty self explanatory. Anyone done this before? UPDATE :
I think my question is somewhat similar to CaptainPicard's but dissimilar enough that I
I think this question is rather easy for you shell scripting monsters. I am
I think the question title is clear enough: is is possible to stable_sort() a
I think the question is a bit silly, but for a newbie startup building
I think this question may end up being a bit subjective so I'm marking

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.