Computer room charge system calculation of billing and billing generation

Source: Internet
Author: User

When doing this piece, it involves a lot of computational problems, of course, are some subtraction simple calculation, although simple, but to use code to achieve it, it is a bit dizzy, because we calculate the data are from the database.

In fact, the calculation of the program code is very simple, because we do not contact, so we will feel chaos, do not know how to do. However, people still rely on their own ideas to write the code, but the method is not the same, for a simple example:

For example, we want to calculate the sum of all the data of the field Addmoney in the recharge_info of the Recharge record table in the database, that is, the total amount of the recharge Summoney.

Most people are the accumulation of the implementation of the host language, that is, the use of query statements to detect all the records, and then use the Loop statement to the field Addmoney all the data traversal, and then add, the specific implementation of the following:

    txtSQL = "SELECT * from Recharge_info"
    Set MRC = ExecuteSQL (txtSQL, Msgtext)
    If MRC. RecordCount > 0 Then
        rechargemoney = 0 do
        -not MRC. EOF
            Rechargemoney = Rechargemoney + Mrc!addmoney
            MRC. MoveNext
        Loop End
    If
    MRC. Close


But I didn't think in the first place to add to the host language, because I remember clearly that when learning a database, a SELECT statement can use a mathematical function that can be used to summarize and aggregate data, such as: count (field name or * number) is used to count the number of records in the results, SUM () function is passed to it as an argument, all the values in an expression are added together, and the expression can be either the name of the column or the result of a calculation, and the AVG () function is the average of a column or an expression in the result set, and Max () and Min (). I'm sure you all know what these two functions are. That's right. is to find the extremum of the result set.

With this in hand, we can use another method to give the computing task to the DBMS. Specifically implemented as follows:

    txtsql = "Select sum (Addmoney) from Recharge_info"
    Set MRC = ExecuteSQL (txtSQL, Msgtext)
    If MRC. Fields (0) > 0 Then
        rechargemoney = MRC. Fields (0)
    Else
        Rechargemoney = 0 End
    If
    MRC. Close


We see that the two methods have the same amount of code, but there is a difference between execution efficiency and system overhead, especially if there is a lot of data. Imagine if there are 100,000 records, then the application will have to do 100,000 cycles, this is a small amount of time overhead ah.

Furthermore, how many comparisons do you have to make when you return the maximum and minimum values of the results? While it is said that DBMS and SQL are providers of raw data, they are not used to accomplish significant data processing, but some of the most basic work can be given to them.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.