Tolong pilih kategori sesuai, jenis posting (diskusi atau bukan) dan sertakan tag/topik yang sesuai seperti komputer, java, php, mysql, dll. Promosi atau posting tidak pada tempatnya akan kami hapus!
- Bagi Anda yang ingin mendaftar, baca link berikut:
http://diskusiweb.com/discussion/50491/how-to-registrasi-diskusiweb-com-baca-ini-terlebih-dahulu
- Cara menyisipkan kode program supaya tampil rapi dan terformat dengan baik di diskusiweb.com: http://www.diskusiweb.com/discussion/50415/cara-menyisipkan-kode-program-di-diskusiweb-com
- Cara posting gambar/image di post Anda: http://www.diskusiweb.com/discussion/47345/cara-menyisipkan-menyertakan-image-pada-posting/p1

group by data mysql tidak muncul

selamat malam master, saya ada masalah grouping data di mysql,
table saya
CREATE TABLE `espt_1770_pp46` (
`id` int(11) NOT NULL,
`idwp` int(25) NOT NULL,
`tahun` int(11) NOT NULL,
`pph0` varchar(10) NOT NULL,
`pph1` varchar(25) NOT NULL,
`pph2` varchar(50) NOT NULL,
`pph3` varchar(100) NOT NULL,
`pph4` decimal(15,0) NOT NULL,
`pph5` decimal(15,0) NOT NULL,
`waktu` datetime NOT NULL,
`user` varchar(50) NOT NULL
)
data sample saya ini

(13, 3, 2016, '01', '066200411112000', 'KPP PRATAMA MEDAN BELAWAN', 'JL.METAL F NO.1 LINK 19 TANJUNG MULIA', '35000000', '350000', '2018-01-16 17:19:29', 'ADMINISTRATOR'),
(14, 3, 2016, '02', '066200411112000', 'KPP PRATAMA MEDAN BELAWAN', 'JL.METAL F NO.1 LINK 19 TANJUNG MULIA', '40000000', '400000', '2018-01-16 17:19:46', 'ADMINISTRATOR'),
(15, 3, 2016, '03', '066200411112000', 'KPP PRATAMA MEDAN BELAWAN', 'JL.METAL F NO.1 LINK 19 TANJUNG MULIA', '38500000', '385000', '2018-01-16 17:20:02', 'ADMINISTRATOR'),
(16, 3, 2016, '04', '066200411112000', 'KPP PRATAMA MEDAN BELAWAN', 'JL.METAL F NO.1 LINK 19 TANJUNG MULIA', '37500000', '375000', '2018-01-16 17:20:48', 'ADMINISTRATOR'),
(17, 3, 2016, '05', '066200411112000', 'KPP PRATAMA MEDAN BELAWAN', 'JL.METAL F NO.1 LINK 19 TANJUNG MULIA', '41500000', '415000', '2018-01-16 17:21:01', 'ADMINISTRATOR'),
(18, 3, 2016, '06', '066200411112000', 'KPP PRATAMA MEDAN BELAWAN', 'JL.METAL F NO.1 LINK 19 TANJUNG MULIA', '38500000', '385000', '2018-01-16 17:21:15', 'ADMINISTRATOR'),
(19, 3, 2016, '07', '066200411112000', 'KPP PRATAMA MEDAN BELAWAN', 'JL.METAL F NO.1 LINK 19 TANJUNG MULIA', '36500000', '365000', '2018-01-16 17:21:28', 'ADMINISTRATOR'),
(20, 3, 2016, '08', '066200411112000', 'KPP PRATAMA MEDAN BELAWAN', 'JL.METAL F NO.1 LINK 19 TANJUNG MULIA', '37500000', '375000', '2018-01-16 17:21:42', 'ADMINISTRATOR'),
(21, 3, 2016, '09', '066200411112000', 'KPP PRATAMA MEDAN BELAWAN', 'JL.METAL F NO.1 LINK 19 TANJUNG MULIA', '38000000', '380000', '2018-01-16 17:21:55', 'ADMINISTRATOR'),
(22, 3, 2016, '10', '066200411112000', 'KPP PRATAMA MEDAN BELAWAN', 'JL.METAL F NO.1 LINK 19 TANJUNG MULIA', '42000000', '420000', '2018-01-16 17:22:08', 'ADMINISTRATOR'),
(23, 3, 2016, '11', '066200411112000', 'KPP PRATAMA MEDAN BELAWAN', 'JL.METAL F NO.1 LINK 19 TANJUNG MULIA', '41800000', '418000', '2018-01-16 17:22:21', 'ADMINISTRATOR'),
(24, 3, 2016, '12', '066200411112000', 'KPP PRATAMA MEDAN BELAWAN', 'JL.METAL F NO.1 LINK 19 TANJUNG MULIA', '41500000', '415000', '2018-01-16 17:22:31', 'ADMINISTRATOR'),
(1164, 179, 2017, '01', '066200411112000', 'MEDAN BELAWAN', 'JL.METAL F NO.1 LINGK.19 TANJUNG MULIA', '50500000', '505000', '2018-02-04 23:09:53', 'ADMINISTRATOR'),
(1165, 179, 2017, '02', '066200411112000', 'MEDAN BELAWAN', 'JL.METAL F NO.1 LINGK.19 TANJUNG MULIA', '60825000', '608250', '2018-01-26 14:43:46', 'dedek'),
(1166, 179, 2017, '03', '066200411112000', 'MEDAN BELAWAN', 'JL.METAL F NO.1 LINGK.19 TANJUNG MULIA', '58500000', '585000', '2018-01-26 14:43:30', 'dedek'),
(1167, 179, 2017, '04', '066200411112000', 'MEDAN BELAWAN', 'JL.METAL F NO.1 LINGK.19 TANJUNG MULIA', '57570000', '575700', '2018-01-26 14:44:23', 'dedek'),
(1168, 179, 2017, '05', '066200411112000', 'MEDAN BELAWAN', 'JL.METAL F NO.1 LINGK.19 TANJUNG MULIA', '52550000', '525500', '2018-01-26 14:44:52', 'dedek'),
(1169, 179, 2017, '06', '066200411112000', 'MEDAN BELAWAN', 'JL.METAL F NO.1 LINGK.19 TANJUNG MULIA', '58550000', '585500', '2018-01-26 14:45:16', 'dedek'),
(1170, 179, 2017, '07', '066200411112000', 'MEDAN BELAWAN', 'JL.METAL F NO.1 LINGK.19 TANJUNG MULIA', '56525000', '565250', '2018-01-26 14:45:41', 'dedek'),
(1171, 179, 2017, '08', '066200411112000', 'MEDAN BELAWAN', 'JL.METAL F NO.1 LINGK.19 TANJUNG MULIA', '57570000', '575700', '2018-01-26 14:46:15', 'dedek'),
(1172, 179, 2017, '09', '066200411112000', 'MEDAN BELAWAN', 'JL.METAL F NO.1 LINGK.19 TANJUNG MULIA', '58050000', '580500', '2018-01-26 14:46:40', 'dedek'),
(1173, 179, 2017, '10', '066200411112000', 'MEDAN BELAWAN', 'JL.METAL F NO.1 LINGK.19 TANJUNG MULIA', '62070000', '620700', '2018-01-26 14:47:05', 'dedek'),
(1174, 179, 2017, '11', '066200411112000', 'MEDAN BELAWAN', 'JL.METAL F NO.1 LINGK.19 TANJUNG MULIA', '61530000', '615300', '2018-01-26 14:47:32', 'dedek'),
(1175, 179, 2017, '12', '066200411112000', 'MEDAN BELAWAN', 'JL.METAL F NO.1 LINGK.19 TANJUNG MULIA', '61500000', '615000', '2018-01-26 14:48:00', 'dedek');

perintah group saya

1. SELECT idwp,pph1 FROM espt_1770_pp46 GROUP BY pph1 HAVING idwp = '3'
2. SELECT idwp,pph1 FROM espt_1770_pp46 GROUP BY pph1 HAVING idwp = '179'

untuk yg group 1 bisa jalan, sedangkan untuk group 2 tidak mau jalan hasil nya tidak ada,

apakah ada yg salah di database saya?

tolong masukan kan nya master...

tq

Comments

  • masalahnya elo pake HAVING

    HAVING itu jalan setelah proses sampai sebelum HAVING selesai

    biar paham, begini ...
    anggap query elo ada 2 bagian

    SELECT idwp,pph1 FROM espt_1770_pp46 GROUP BY pph1

    itu dijalankan dulu ...
    dapatnya hanya ini :

    idwp | pph1
    3 | 066200411112000

    baru HAVING nya jalan ...
    HAVING idwp = '179'

    ada yg idwp nya 179 ? TIDAK
    cuma ada 1 baris data, dan itu idwp nya 3

    beda cerita kalo elo pake WHERE
    SELECT idwp,pph1 FROM espt_1770_pp46 WHERE idwp=179 GROUP BY pph1

    atau GROUP BY elo juga melibatkan idwp
    SELECT idwp,pph1 FROM espt_1770_pp46 GROUP BY idwp,pph1 HAVING idwp=179

    itu hasilnya sama :

    idwp | pph1
    179 | 066200411112000

    tapi dibanding pake HAVING, lebih baik pake WHERE
    WHERE sudah membatasi data sesuai kondisi saat pengambilan / pengolahan data
    HAVING proses tetap pada seluruh data, hasilnya baru dipilih yg sesuai kondisi
  • mantap master @labalaba sudah jalan setelah saya ganti menjadi

    beda cerita kalo elo pake WHERE
    SELECT idwp,pph1 FROM espt_1770_pp46 WHERE idwp=179 GROUP BY pph1

    atau GROUP BY elo juga melibatkan idwp
    SELECT idwp,pph1 FROM espt_1770_pp46 GROUP BY idwp,pph1 HAVING idwp=179

    tq yah master....^^
Sign In or Register to comment.