Postingan lainnya
cara merubah nilai null menjadi 0 di mysql
jadi saya mau buat tabel persentase 100%, ketika ada tabel yg gak ada nilai nya hasil nya jadi NULL, jadi ketika ditambahkan dengan yg ada nilai nya jadi nilai nya tetap NULL
contoh 1 + 1 = 2 (ada hasilnya)
1 + 0 = NULL (harusnya 1)
ada solusi gan?
jadi harusnya query nya ini
SUM((lancar)/(lancar+kurang_lancar+diragukan+macet+pk))*100 AS lancar,
berhubungan klo ditambah nilai yg 0 jadi NULL (diragukan, macet, pk), jadi saya tulis query nya yg ada hasilnya aja
SELECT SUM((lancar)/(lancar+kurang_lancar))*100 AS lancar,
SUM((kurang_lancar)/(lancar+kurang_lancar))*100 AS kurang_lancar,
SUM((diragukan)/(lancar+kurang_lancar))*100 AS diragukan,
SUM((macet)/(lancar+kurang_lancar))*100 AS macet,
SUM((pk)/(lancar+kurang_lancar))*100 AS PK
FROM keseluruhan;
Screenshot (437).png
Tanggapan
coba berikan struktur tabel mysql nya.
1 Jawaban:
<div>problem solved<br>pake ini</div><pre>SELECT SUM(COALESCE(lancar,0)/(COALESCE(lancar,0)+COALESCE(kurang_lancar,0)+COALESCE(diragukan,0)+COALESCE(macet,0)+COALESCE(pk,0)))*100 AS lancar, SUM(COALESCE(kurang_lancar,0)/(COALESCE(lancar,0)+COALESCE(kurang_lancar,0)+COALESCE(diragukan,0)+COALESCE(macet,0)+COALESCE(pk,0)))*100 AS kurang_lancar, SUM(COALESCE(diragukan,0)/(COALESCE(lancar,0)+COALESCE(kurang_lancar,0)+COALESCE(diragukan,0)+COALESCE(macet,0)+COALESCE(pk,0)))*100 AS diragukan, SUM(COALESCE(macet,0)/(COALESCE(lancar,0)+COALESCE(kurang_lancar,0)+COALESCE(diragukan,0)+COALESCE(macet,0)+COALESCE(pk,0)))*100 AS macet, SUM(COALESCE(pk,0)/(COALESCE(lancar,0)+COALESCE(kurang_lancar,0)+COALESCE(diragukan,0)+COALESCE(macet,0)+COALESCE(pk,0)))*100 AS PK FROM keseluruhan;</pre>