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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:26:04+00:00 2026-06-04T19:26:04+00:00

I am running a MySql database through phpmyadmin and am working on building a

  • 0

I am running a MySql database through phpmyadmin and am working on building a query to total some values.

In EXCEL the formula looks like this =IF(AND(P6=P5,B6=B5),SUM(H5+F6),F6)

That formula is put in the H column

P Column is a class identifier. B Column is their registration number. H Column is their total points. F column is the point value of their entry.

It works great in excel. But having some troubles in the syntax for SQL.

I know that first I need to sort the file so that everything comes through in the correct order, got that. But from that point on I am clueless.

If a more in depth explanation is needed for my excel code I can do that, if it helps.

  • 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-04T19:26:06+00:00Added an answer on June 4, 2026 at 7:26 pm

    As far as I understand you need running total with some “partitioning” or rows. It seems that in MySql you need to do some “hacking” with variables, as analytic functions are not available in this database.

    Following query will do it. It uses three variables – @rollingsum to store sum of F column, and @prevP and @prevB variables to store previous value of B and P columns)

    SELECT s.p, s.b, s.f, s.rollingSum FROM 
    (
    SELECT  p, 
            b, 
            f, 
            IF( p=@prevP AND b=@prevB,
            @rollingsum := @rollingsum + f,
            @rollingsum := f )  as rollingSum,
            @prevP := p,
            @prevB := b
    FROM      test_table p, (SELECT @rollingsum := 0, @prevP := '', @prevB := '') r 
    ORDER BY  p,b ) s
    

    Example:

    Source data:

    P   B   F
    1   1   10
    1   1   10
    1   2   10
    1   2   10
    1   2   10
    2   2   10
    2   2   10
    2   2   10
    

    Result for the above query (rollingsum column is your H column – total points in your excel):

    P   B   F   ROLLINGSUM
    1   1   10  10
    1   1   10  20
    1   2   10  10
    1   2   10  20
    1   2   10  30
    2   2   10  10
    2   2   10  20
    2   2   10  30
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been working on a mysql database that I set up with phpmyadmin...
after adding about 6k of lines into my mySQL database through Python, some letters
I exported a live MySQL database (running mysql 5.0.45) to a local copy (running
I'm using Subsonic 3.0.0.3 with ActiveRecord, running against a MySQL database. I'm finding that
I'm trying to move a MySQL database from a Linux machine to one running
I'm running Mysql 5.0.77 and I'm pretty sure this query should work? SELECT *
the current SQL query works fine locally on MAMP 1.8.4 running MySQL 5.1.37. SELECT
I have phpmyadmin running on a remote VPS. It has been working fine for
I have a production database server running on MYSQL 5.1, now we need to
I work on a Joomla web site, installed on a MySQL database and running

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.