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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:55:42+00:00 2026-05-26T06:55:42+00:00

I’m trying to calculate churn using one mysql query… I can do this in

  • 0

I’m trying to calculate churn using one mysql query… I can do this in PHP, but it would be very helpful if mysql could do it.

Here’s my query:

SELECT 
  bill_date_bil,
  account_number_bil,
 SUM(amount_bil)


FROM
  billing_bil 
WHERE account_number_bil = 20017
  AND type_bil <> 'CA' 
  AND type_bil <> 'CK' 
GROUP BY period (bill_date_bil)
ORDER BY bill_date_bil ASC

and here’s what I get:

bill_date_bil  account_number_bil  sum(amount_bil)
-------------  ------------------  ---------------
2007-09-01                  20017        3498.5000
2007-10-01                  20017        8248.5000
2007-11-01                  20017        9886.0000
2007-12-01                  20017        9411.0000
2008-01-01                  20017        9411.0000
2008-02-01                  20017        9411.0000
2008-03-01                  20017       -6151.5000
2008-04-01                  20017        6118.5400
2008-05-01                  20017       11171.9800
2008-06-01                  20017        6434.3800
2008-07-01                  20017        6434.3800

I would like to have another column that gives me the difference between the current bill and the previous months bill.

Thoughts?

here’s what I need:

bill_date_bil   account_number_bil  sum(amount_bil) churn
-------------   ------------------  --------------- 
9/1/2007    20017   3498.5                         0
10/1/2007   20017   8248.5                        4750
11/1/2007   20017   9886                           1637.5
12/1/2007   20017   9411                        -475
1/1/2008    20017   9411                           0
2/1/2008    20017   9411                           0
3/1/2008    20017   -6151.5                       -15562.5
4/1/2008    20017   6118.54                         12270.04
5/1/2008    20017   11171.98                            5053.44
6/1/2008    20017   6434.38                         -4737.6
7/1/2008    20017   6434.38                         0
  • 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-26T06:55:42+00:00Added an answer on May 26, 2026 at 6:55 am

    Use this:

    SET @sum_bill=0;
    SELECT 
      bill_date_bil,
      account_number_bil,
     SUM(amount_bil),
    @sum_bill := @sum_bill+SUM(amount_bil)
    
    
    FROM
      billing_bil 
    WHERE account_number_bil = 20017
      AND type_bil <> 'CA' 
      AND type_bil <> 'CK' 
    GROUP BY period (bill_date_bil)
    ORDER BY bill_date_bil ASC
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to create an if statement in PHP that prevents a single post
I am reading a book about Javascript and jQuery and using one of the

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.