[sql] 1

Viewer

  1. SELECT
  2.     stat.*
  3. FROM bg_object_mapping om
  4.          LEFT JOIN (
  5.     SELECT
  6.         stat.*
  7.     FROM staging.stats_columns stat
  8.              JOIN (
  9.         SELECT
  10.             external_id,
  11.             source_name
  12.         FROM bg_object_mapping
  13.         WHERE business_id = :businessId
  14.     ) idmap
  15.                   ON stat.external_id = idmap.external_id
  16.                       AND stat.source_name = idmap.source_name
  17.              JOIN (
  18.         SELECT
  19.             external_id,
  20.             source_name
  21.         FROM bg_object_mapping
  22.         WHERE business_id = :businessId
  23.     ) par_idmap
  24.                   ON stat.parent = par_idmap.external_id
  25.                       AND stat.source_name = par_idmap.source_name
  26. ) stat
  27.                    ON om.external_id = stat.external_id
  28.                        AND om.source_name = stat.source_name

Editor

You can edit this paste and save as new:


File Description
  • 1
  • Paste Code
  • 30 Jun-2024
  • 860 Bytes
You can Share it: