Skip to content

Instantly share code, notes, and snippets.

@hidayat365
Created May 19, 2014 06:20
Show Gist options
  • Select an option

  • Save hidayat365/4a432eda27da263d0441 to your computer and use it in GitHub Desktop.

Select an option

Save hidayat365/4a432eda27da263d0441 to your computer and use it in GitHub Desktop.
UNION ALL sample
mysql> use test;
Database changed
mysql> drop view if exists qry_labarugi ;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> create view qry_labarugi as
-> SELECT year(tanggal) AS tahun
-> , month(tanggal) AS bulan
-> , SUM(total_jual) AS total
-> FROM tbl_penjualan
-> GROUP BY year(tanggal)
-> , month(tanggal)
->
-> UNION ALL
-> SELECT year(tanggal) AS tahun
-> , month(tanggal) AS bulan
-> , SUM(total_beli) AS total
-> FROM tbl_pembelian
-> GROUP BY year(tanggal)
-> , month(tanggal)
->
-> UNION ALL
-> SELECT year(tanggal) AS tahun
-> , month(tanggal) AS bulan
-> , SUM(jumlah) AS total
-> FROM tbl_pengeluaran
-> GROUP BY year(tanggal)
-> , month(tanggal)
->
-> ;
Query OK, 0 rows affected (0.04 sec)
mysql> select * from qry_labarugi;
Empty set (0.00 sec)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment