Wednesday, 15 July 2015

mysql - How To select Query -



mysql - How To select Query -

i have table view named tes.

+--------------+--------------+------+-----+---------+-------+ | field | type | null | key | default | | +--------------+--------------+------+-----+---------+-------+ | id_oba | int(11) | no | | null | | | nama_obat | varchar(120) | no | | null | | | satuan | varchar(20) | yes | | null | | | stok_awal | int(5) | yes | | null | | | persediaan | int(5) | yes | | null | | | nama_suplier | varchar(30) | no | | null | | | pemakaian | int(4) | no | | null | | | tanggal | date | yes | | null | | +--------------+--------------+------+-----+---------+-------+

when execute:

select id_oba, nama_obat, satuan, stok_awal, sum(pemakaian) pemakaian, persediaan, tes grouping id_oba;

i result:

+--------+-----------+--------+-----------+-----------+------------+ | id_oba | nama_obat | satuan | stok_awal | pemakaian | persediaan | +--------+-----------+--------+-----------+-----------+------------+ | 1 | paramex | botol | 30 | 40 | 5 | | 2 | oskadon | botol | 30 | 41 | 27 | | 3 | lindon | botol | 31 | 30 | 4 | +--------+-----------+--------+-----------+-----------+------------+

how can modify query result this?

+--------+-----------+--------+-----------+-----------+------------+-------+ | id_oba | nama_obat | satuan | stok_awal | pemakaian | persediaan | total | +--------+-----------+--------+-----------+-----------+------------+-------+ | 1 | paramex | botol | 30 | 40 | 5 | 45 | | 2 | oskadon | botol | 30 | 41 | 27 | 67 | | 3 | lindon | botol | 31 | 30 | 4 | 34 | +--------+-----------+--------+-----------+-----------+------------+-------+

please help me problem.

thanks.

change this

select id_oba, nama_obat, satuan, stok_awal, sum(pemakaian) pemakaian, persediaan,(sum(pemakaian)+persediaan) total tes grouping id_oba;

mysql select

No comments:

Post a Comment