Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
BALANCE
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
drop table if exists xPayments; drop table if exists xTransactions; drop table if exists xTransaction_Items; create table xPayments(id int, amount int, date timestamp, transaction_id int); create table xTransactions(id int, number int, date timestamp, val int); create table xTransaction_Items(id int, transaction_id int, description varchar(100), price int, discount int, quantity int); select t.number, DATE(p.date), ti.total 'total', SUM(p.amount) 'paid', ti.total - (select sum(inner_p.amount) from xpayments inner_p where inner_p.transaction_id = p.id and inner_p.date <= p.date ) 'balance' from xpayments p left join xtransactions t on p.transaction_id = t.id left join ( select inner_ti.transaction_id, sum((inner_ti.price - inner_ti.discount) * inner_ti.quantity) 'total' from xtransaction_items inner_ti group by inner_ti.transaction_id ) ti on t.id = ti.transaction_id group by t.number, DATE(p.date), ti.total, 'balance' order by DATE(p.date) ASC; drop table if exists xPayments; drop table if exists xTransactions; drop table if exists xTransaction_Items;
absolute service time: 0,36 sec
edit mode
|
history