PostgreSQL for accumulator

2010-12-21  来源:本站原创  分类:Database  人气:79 

exchange=# select invoice_id, client_id , total_amount,invoice_end   from  invoice   order by invoice_id ;
 invoice_id | client_id | total_amount |      invoice_end
------------+-----------+--------------+------------------------
         31 |         1 |     14.06202 | 2010-12-20 00:00:00+00
         71 |         4 |    -45.25617 | 2010-12-20 00:00:00+00
         75 |         3 |      2.52500 | 2010-12-17 00:00:00+00
         76 |         3 |      9.36850 | 2010-12-18 00:00:00+00
         77 |         3 |     34.40367 | 2010-12-19 00:00:00+00
         78 |         3 |      0.00000 | 2010-12-20 00:00:00+00
(6 rows)

exchange=#

Now total_amount cumulative

exchange=# select
 invoice.invoice_id, invoice.client_id ,invoice. total_amount,invoice.invoice_end,
 (select sum(total_amount) as past_due from invoice as inner_invoice where client_id = invoice.client_id and inner_invoice.invoice_end <= invoice.invoice_end) as grand_total
 from invoice  order  by invoice.invoice_id;
 invoice_id | client_id | total_amount |      invoice_end       | grand_total
------------+-----------+--------------+------------------------+-------------
         31 |         1 |     14.06202 | 2010-12-20 00:00:00+00 |    14.06202
         71 |         4 |    -45.25617 | 2010-12-20 00:00:00+00 |   -45.25617
         75 |         3 |      2.52500 | 2010-12-17 00:00:00+00 |     2.52500
         76 |         3 |      9.36850 | 2010-12-18 00:00:00+00 |    11.89350
         77 |         3 |     34.40367 | 2010-12-19 00:00:00+00 |    46.29717
         78 |         3 |      0.00000 | 2010-12-20 00:00:00+00 |    46.29717
(6 rows)

exchange=#

grand_total field for the cumulative

相关文章
  • PostgreSQL for accumulator 2010-12-21

    exchange=# select invoice_id, client_id , total_amount,invoice_end from invoice order by invoice_id ; invoice_id | client_id | total_amount | invoice_end ------------+-----------+--------------+------------------------ 31 | 1 | 14.06202 | 2010-12-20

  • window under the rails with postgresql connection error solution 2009-04-09

    This was supposed to go out last Saturday, but my blog took precedence. Oh, that, and Fable 2. Shh. If you've somehow found this post in search of an answer, I have nothing but a rant for you. If the post at Robby on Rails did not work ... you're out

  • Record of Study PostgreSQL jdbc connection and configuration hibernet 2009-04-13

    1, jdbc link to tomcat as an example: / psqlJDBC / under postgresql-8.3-603.jdbc4.jar files are copied to the Tomcat \ common \ lib \ under. server.xml Resource configuration is as follows: driverClassName = "org.postgresql.Driver" url = "j

  • postgresql in windows (including win7) installation and configuration under 2010-02-04

    First of all, the following is commonly used commands: ③ initdb initialize database. ④ pg_ctl start start the database ⑤ pg_ctl stop to stop the establishment of a database ⑥ post_svc-install windows nt service (need to set system environment variabl

  • Access to the database postgresql 2010-02-04

    Once you create a database, you can access it: Running PostgreSQL interactive terminal program, called psql, which allows you to interactively enter, edit, and implementation of SQL commands. Graphical front-end to use our existing tools, such as PgA

  • Postgresql source basis in the spinlock: TAS 2010-02-07

    PostgreSQL using spinlock to lock on resources. TAS lock is the simplest spinlock. Of course, semaphores spinlock can be achieved. But according to PostgreSQL's early report, the kernel semaphore provided will greatly reduce performance. So learning

  • In postgresql using plpgsql function returns the record set (change) 2010-02-15

    Keywords: Recently used in a project in a pg (postgresql), customers need a lot of forms, there is a typical Chinese-style statements (contact with people who know very complicated), so divided the two kinds of ways to solve: First, do not need to Yo

  • Access postgreSQL database using nhibernate 2010-04-01

    Using nhibernate access postgreSQL database is relatively simple, first introduce the development environment. postgreSQL 8.4 NHibernate 2.1.2.4000 Npgsql 2.0.8 Npgsql is postgreSQL's. Net database-driven, available here to download. NHibernate dll w

  • Web-based PostgreSQL database management tool 2010-02-28

    phpPgAdmin is a web-based PostgreSQL database management tools. Development Language: PHP Operating system: Software Home Page: http://phppgadmin.sourceforge.net/ Document addresses: Download: http://phppgadmin.sourceforge.net/?page=download Your tim

  • When installing postgresql "An error occured executing the Microsoft VC + + runtime install" solution 2010-03-04

    In the XP install postgresql database pop-up "An error occured executing the Microsoft VC + + runtime installer" error message, specific solutions are as follows: 1. Open the Run dialog box, enter "C: \ WINDOWS \ inf" 2. In the inf dir

  • [Reprinted] Ubuntu install Postgresql 8.3 2010-03-08

    In the Ubuntu install Postgresql and pgAdmin3 sudo apt-get install postgresql-8.3 postgresql-client-8.3 postgresql-contrib-8.3 sudo apt-get install pgadmin3 These instructions to install the client and server, some additional tools, pgAdmin3 can work

  • opensuse install postgresql source 2010-03-14

    ubuntu 9.10 inexplicable failure to debug the final out of the main interface embodied in the ddd after the input box are not written. Helpless, he moved to opensuse 11.2. The following is the full source installation of postgresql process: 1 to post

  • postgresql installation of the windows platform 2010-03-17

    Reprinted: postgresql installed under the windows platform, a day after a night of torture, finally postgresql normal running on my computer, although still some instability, but finally it is used, no BS, tell me on the following configuration proce

  • java data tables on PostgreSQL backup 2010-03-29

    // Backup data table public static String backup(String dbname,String tablename) { String backupName=""; try { Runtime rt = Runtime.getRuntime(); // Call MySQL cmd: Process child = rt .exec("C:\\Program Files\\PostgreSQL\\8.2\\bin\\pg_dump.

  • Write a batch file on the PostgreSQL backup and recovery bat 2010-03-29

    Create a bat file, add the following code CLS has played a clear echo of the role of backup command: cd C: \ Program Files \ PostgreSQL \ 8.2 \ bin \ CLS pg_dump-U postgres-d GZMapDB-t gz_bus> d: \ gz-bus.backup pause Recovery: cd C: \ Program Files

  • PostgreSQL database service could not start the solution 2010-03-30

    Because the customer side of the disk is generally FAT32 file system, so we installed, the use of manually install PostgreSQL database in the form of installation, but the group successfully initialize the database and successfully register the syste

  • In Slackware PostgreSQL support for the PHP compiler 2010-03-04

    Slackware does not pre-installed PostgreSQL, installed from the slackbuild.org PostgreSQL. Then start the following compile PHP's PostgreSQL support. First, check the PHP version, Slackware13 pre-installed is PHP5.2.10, from the php.net download the

  • postgresql installation steps 2010-04-14

    postgresql installation steps: sudo apt-get install libreadline5-dev sudo apt-get install zlib1g-dev An official document of the steps . / Configure make su make install adduser postgres mkdir / usr / local / pgsql / data chown postgres / usr / local

  • Nginx, PostgreSQL And Trac: preparatory work 2010-04-18

    This involves the operating system to Linux uname -a Linux localhost 2.6.18-164.11.1.el5 #1 SMP Mon Mar 8 20:38:10 CST 2010 x86_64 x86_64 x86_64 GNU/Linux Need to install the software, including Nginx, PostgreSQL, Python, Trac In fact, the software i

  • Postgresql installation process 2010-05-09

    The project before doing their own installation process Postgresql, recording a bit (only done for the project). • Check installation # Yum list installed | grep postgre * Uninstall example, the following operation. postgresql-devel, postgresql-serve