2 コミット 8f46510765 ... ea1a59d7cb

作者 SHA1 メッセージ 日付
  weijianghai ea1a59d7cb init 3 週間 前
  weijianghai 8f46510765 init 3 週間 前
1 ファイル変更4 行追加20 行削除
  1. 4 20
      doc/sql.md

+ 4 - 20
doc/sql.md

@@ -5,11 +5,7 @@
 ```sql
 with t101 as (
 select
-    (
-    select
-        max(year_month)
-    from
-        car.car_yue_jie) as year_month,
+    TO_CHAR(CURRENT_DATE - INTERVAL '1 month', 'YYYYMM') as year_month,
     first_unit,
     count(1) as total,
     count(shi_fou_zhi_xing_zhong_yue_jie = '是' or null) as ls,
@@ -17,11 +13,7 @@ select
 from
     car.car_yue_jie
 where
-    year_month = (
-    select
-        max(year_month)
-    from
-        car.car_yue_jie)
+    year_month = TO_CHAR(CURRENT_DATE - INTERVAL '1 month', 'YYYYMM')::int4
 group by
     first_unit
 ),
@@ -54,11 +46,7 @@ from
 with
 t101 as (
 select
-    (
-    select
-        max(month_id)
-    from
-        car.car_fee_hb) as month_id,
+    TO_CHAR(CURRENT_DATE - INTERVAL '1 month', 'YYYYMM') as month_id,
     second_org_no,
     second_org_name,
     round(sum(case when kpi_id in ('KPI_001', 'KPI_002', 'KPI_004', 'KPI_005', 'KPI_006', 'KPI_007', 'KPI_008', 'KPI_009', 'KPI_010', 'KPI_011', 'KPI_013', 'KPI_014', 'KPI_015', 'KPI_016', 'KPI_017', 'KPI_018', 'KPI_019', 'KPI_020', 'KPI_021', 'KPI_022', 'KPI_023') then ty_value else 0 end) / 10000, 2) as ty_fy,
@@ -67,11 +55,7 @@ from
     car.car_fee_hb
 where
     second_org_no is not null
-    and month_id = (
-    select
-        max(month_id)
-    from
-        car.car_fee_hb)
+    and month_id = TO_CHAR(CURRENT_DATE - INTERVAL '1 month', 'YYYYMM')::int4
 group by
     second_org_no,
     second_org_name