CREATE TEMPORARY TABLE local AS SELECT row_number() over(order by grid_person_basic.office_community) no, grid_person_basic.office_community,kpi_office_grid_basic.office_community FROM grid_person_basic LEFT JOIN kpi_office_grid_basic ON grid_person_basic.office_community = kpi_office_grid_basic.office_community_id SELECT RIGHT(local.office_community(1), 1) as last_char, COUNT(*) as count, local.office_community(1) FROM local LEFT JOIN kpi_office_grid_basic ON local.office_community = kpi_office_grid_basic.office_community_id GROUP BY last_char;每行代码的含义
时间: 2023-08-05 16:03:53 浏览: 124
Temp-Table-In-Oracle.rar_TEMP TABLE orac_Table_oracle ppt
让我为你解释每行代码的含义:
1. `CREATE TEMPORARY TABLE local AS`:创建一个名为 `local` 的临时表。
2. `SELECT row_number() over(order by grid_person_basic.office_community) no, grid_person_basic.office_community, kpi_office_grid_basic.office_community`:从 `grid_person_basic` 表和 `kpi_office_grid_basic` 表中选择列,并给第一列起名为 `no`,第二列为 `grid_person_basic.office_community`,第三列为 `kpi_office_grid_basic.office_community`。`row_number() over(order by grid_person_basic.office_community)` 是一个窗口函数,用于为每行数据生成一个序号。
3. `FROM grid_person_basic LEFT JOIN kpi_office_grid_basic ON grid_person_basic.office_community = kpi_office_grid_basic.office_community_id`:从 `grid_person_basic` 表左连接到 `kpi_office_grid_basic` 表,使用 `grid_person_basic.office_community` 和 `kpi_office_grid_basic.office_community_id` 列进行连接。
4. `SELECT RIGHT(local.office_community(1), 1) as last_char, COUNT(*) as count, local.office_community(1)`:从 `local` 表中选择列,并给第一列起名为 `last_char`,第二列为 `count`,第三列为 `local.office_community(1)`。`RIGHT(local.office_community(1), 1)` 是一个字符串函数,用于获取 `local.office_community(1)` 字符串的最后一个字符。
5. `FROM local LEFT JOIN kpi_office_grid_basic ON local.office_community = kpi_office_grid_basic.office_community_id`:从 `local` 表左连接到 `kpi_office_grid_basic` 表,使用 `local.office_community` 和 `kpi_office_grid_basic.office_community_id` 列进行连接。
6. `GROUP BY last_char`:按照 `last_char` 列进行分组。
以上是每行代码的含义和作用。请注意,对于第四行代码中的 `local.office_community(1)`,我认为这是一个错误,因为在 SQL 中不应该在列名后面使用 `(1)` 的语法。你可能需要根据实际需求对其进行修改。
阅读全文