| | 363 | {{{ |
| | 364 | WITH VetCenterVisitData AS ( |
| | 365 | SELECT |
| | 366 | vc.id AS vet_center_id, |
| | 367 | vc.name AS vet_center_name, |
| | 368 | COUNT(pc.id) AS total_visits, |
| | 369 | COUNT(DISTINCT j.id) AS total_jobs |
| | 370 | FROM |
| | 371 | vet_centers vc |
| | 372 | LEFT JOIN |
| | 373 | pet_cares pc ON vc.id = pc.vetcentersID |
| | 374 | LEFT JOIN |
| | 375 | jobs j ON vc.id = j.vetCentersID |
| | 376 | GROUP BY |
| | 377 | vc.id |
| | 378 | ), |
| | 379 | TotalVisitCount AS ( |
| | 380 | SELECT |
| | 381 | SUM(total_visits) AS total_visits_all_centers |
| | 382 | FROM |
| | 383 | VetCenterVisitData |
| | 384 | ) |
| | 385 | SELECT |
| | 386 | vcd.vet_center_name, |
| | 387 | vcd.total_visits, |
| | 388 | vcd.total_jobs, |
| | 389 | ROUND((vcd.total_visits::decimal / tvc.total_visits_all_centers) * 100, 2) AS visit_percentage |
| | 390 | FROM |
| | 391 | VetCenterVisitData vcd, |
| | 392 | TotalVisitCount tvc |
| | 393 | ORDER BY |
| | 394 | visit_percentage DESC; |
| | 395 | }}} |