perf(cpone): optimize cooperation tariff count
This commit is contained in:
@@ -103,10 +103,15 @@ func (r MySQLLayananRepository) ListTarifKerjasama(ctx context.Context, params T
|
||||
query := `SELECT pt.Perusahaan_TarifID, pt.PerusahaanID, p.KodePerusahaan,
|
||||
p.Nama, pt.PenanggungJawab, p.Alamat, pt.TeleponPenanggungJawab,
|
||||
pt.EmailPenanggungJawab,
|
||||
(SELECT COUNT(*) FROM perusahaan_grouptarif pg
|
||||
WHERE pg.Perusahaan_TarifID = pt.Perusahaan_TarifID AND pg.NA = 'N')
|
||||
COALESCE(pg.JumlahGroupTarif, 0)
|
||||
FROM perusahaan_tarif pt
|
||||
INNER JOIN perusahaan p ON p.PerusahaanID = pt.PerusahaanID ` + where + `
|
||||
INNER JOIN perusahaan p ON p.PerusahaanID = pt.PerusahaanID
|
||||
LEFT JOIN (
|
||||
SELECT Perusahaan_TarifID, COUNT(*) AS JumlahGroupTarif
|
||||
FROM perusahaan_grouptarif
|
||||
WHERE NA = 'N'
|
||||
GROUP BY Perusahaan_TarifID
|
||||
) pg ON pg.Perusahaan_TarifID = pt.Perusahaan_TarifID ` + where + `
|
||||
ORDER BY p.Nama, pt.Perusahaan_TarifID
|
||||
LIMIT ? OFFSET ?`
|
||||
queryArgs := append(append([]any{}, args...), params.PerPage, (params.Page-1)*params.PerPage)
|
||||
|
||||
Reference in New Issue
Block a user