Advertisement
temaon_lieto

Untitled

Dec 20th, 2023 (edited)
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Два запроса для второй страницы (Сторінка "Індикатори якості надання ПМД". Розділ "Декларації")
  2. =================================================================================================
  3.  
  4. SELECT "dbo"."Employees"."Id",
  5.        CONCAT_WS(' ', "dbo"."Parties"."LastName", "dbo"."Parties"."FirstName")                               as fullname,
  6.        "dbo"."Employees"."PositionRefId",
  7.        COUNT(declarations.id)                                                                                as total_counter,
  8.        COUNT(declarations.id) filter ( where EXTRACT(YEAR FROM AGE(cast("personalities"."birth_date" as date))) <=
  9.                                              5 )                                                             as age_0_5_counter,
  10.        COUNT(declarations.id)
  11.        filter ( where EXTRACT(YEAR FROM AGE(cast("personalities"."birth_date" as date))) BETWEEN 6 AND 17 )  as age_6_17_counter,
  12.        COUNT(declarations.id)
  13.        filter ( where EXTRACT(YEAR FROM AGE(cast("personalities"."birth_date" as date))) BETWEEN 18 AND 39 ) as age_18_39_counter,
  14.        COUNT(declarations.id)
  15.        filter ( where EXTRACT(YEAR FROM AGE(cast("personalities"."birth_date" as date))) BETWEEN 40 AND 64 ) as age_40_64_counter,
  16.        COUNT(declarations.id) filter ( where EXTRACT(YEAR FROM AGE(cast("personalities"."birth_date" as date))) >=
  17.                                              65 )                                                          as age_65_final_counter
  18. FROM "dbo"."Employees"
  19.          INNER JOIN "dbo"."Parties" ON "dbo"."Employees"."PartyId" = "dbo"."Parties"."Id"
  20.          INNER JOIN "dbo"."Parties" "parties_dbo_Employees_join"
  21.                     ON "parties_dbo_Employees_join"."Id" = "dbo"."Employees"."PartyId"
  22.          INNER JOIN "dbo"."LegalEntities" ON "dbo"."LegalEntities"."Id" = "parties_dbo_Employees_join"."LegalEntityId"
  23.          INNER JOIN "declarations" ON "declarations"."employee_id" = "dbo"."Employees"."Id"
  24.          INNER JOIN "personalities" ON "personalities"."id" = "declarations"."personality_id" AND
  25.                                        "personalities"."type" = 'Patient::Person'
  26.          INNER JOIN "user_patients" ON "user_patients"."personality_id" = "personalities"."id"
  27.          INNER JOIN "declaration_statuses" ON "declaration_statuses"."id" = "declarations"."declaration_status_id"
  28. WHERE "dbo"."Parties"."LegalEntityId" = 867
  29.   AND "dbo"."Employees"."EmployeeTypeRefValue" = 'DOCTOR'
  30.   AND ("dbo"."Employees"."EmployeeStatusRefValue" = 'APPROVED')
  31.   AND "declaration_statuses"."code" = 'ACTIVE'
  32.   AND ("dbo"."LegalEntities"."Id" = 867)
  33. GROUP BY "dbo"."Employees"."Id", CONCAT_WS(' ', "dbo"."Parties"."LastName", "dbo"."Parties"."FirstName");
  34.  
  35. ###################
  36.  
  37. SELECT COUNT(DISTINCT "dbo"."Employees"."Id")                                                                         as total_employee_counter,
  38.        COUNT(DISTINCT "dbo"."Employees"."Id")
  39.        filter ( where "dbo"."PositionRefs"."Value" = 'P7' )                                                           as p7_position_counter,
  40.        COUNT(DISTINCT "dbo"."Employees"."Id")
  41.        filter ( where "dbo"."PositionRefs"."Value" = 'P8' )                                                           as p8_position_counter,
  42.        COUNT(DISTINCT "dbo"."Employees"."Id")
  43.        filter ( where "dbo"."PositionRefs"."Value" = 'P9' )                                                           as p9_position_counter,
  44.        COUNT(DISTINCT "dbo"."Employees"."Id")
  45.        filter ( where "dbo"."PositionRefs"."Value" = 'P10' )                                                          as p10_position_counter,
  46.        COUNT(DISTINCT "dbo"."Employees"."Id")
  47.        filter ( where "dbo"."PositionRefs"."Value" = 'P11' )                                                          as p11_position_counter,
  48.        COUNT(declarations.id)                                                                                         as total_counter,
  49.        COUNT(declarations.id) filter (where EXTRACT(YEAR FROM AGE(cast("personalities"."birth_date" as date))) <=
  50.                                             5 )                                                                       as age_0_5_counter,
  51.        COUNT(declarations.id)
  52.        filter ( where EXTRACT(YEAR FROM AGE(cast("personalities"."birth_date" as date))) BETWEEN 6 AND 17 )           as age_6_17_counter,
  53.        COUNT(declarations.id)
  54.        filter ( where EXTRACT(YEAR FROM AGE(cast("personalities"."birth_date" as date))) BETWEEN 18 AND 39 )          as age_18_39_counter,
  55.        COUNT(declarations.id)
  56.        filter ( where EXTRACT(YEAR FROM AGE(cast("personalities"."birth_date" as date))) BETWEEN 40 AND 64 )          as age_40_64_counter,
  57.        COUNT(declarations.id) filter ( where EXTRACT(YEAR FROM AGE(cast("personalities"."birth_date" as date))) >=
  58.                                              65 )                                                                     as age_65_final_counter
  59. FROM "dbo"."Employees"
  60.          INNER JOIN "dbo"."Parties" ON "dbo"."Employees"."PartyId" = "dbo"."Parties"."Id"
  61.          INNER JOIN "dbo"."PositionRefs" ON "dbo"."PositionRefs"."Id" = "dbo"."Employees"."PositionRefId"
  62.          INNER JOIN "dbo"."Parties" "parties_dbo_Employees_join"
  63.                     ON "parties_dbo_Employees_join"."Id" = "dbo"."Employees"."PartyId"
  64.          INNER JOIN "dbo"."LegalEntities" ON "dbo"."LegalEntities"."Id" = "parties_dbo_Employees_join"."LegalEntityId"
  65.          INNER JOIN "declarations" ON "declarations"."employee_id" = "dbo"."Employees"."Id"
  66.          INNER JOIN "personalities" ON "personalities"."id" = "declarations"."personality_id" AND
  67.                                        "personalities"."type" = 'Patient::Person'
  68.          INNER JOIN "user_patients" ON "user_patients"."personality_id" = "personalities"."id"
  69.          INNER JOIN "declaration_statuses" ON "declaration_statuses"."id" = "declarations"."declaration_status_id"
  70. WHERE "dbo"."Parties"."LegalEntityId" = 867
  71.   AND "dbo"."Employees"."EmployeeTypeRefValue" = 'DOCTOR'
  72.   AND ("dbo"."Employees"."EmployeeStatusRefValue" = 'APPROVED')
  73.   AND "declaration_statuses"."code" = 'ACTIVE'
  74.   AND ("dbo"."LegalEntities"."Id" = 867)
  75. GROUP BY "dbo"."LegalEntities"."Id";
  76.  
  77.  
  78.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement