Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Два запроса для второй страницы (Сторінка "Індикатори якості надання ПМД". Розділ "Декларації")
- =================================================================================================
- SELECT "dbo"."Employees"."Id",
- CONCAT_WS(' ', "dbo"."Parties"."LastName", "dbo"."Parties"."FirstName") as fullname,
- "dbo"."Employees"."PositionRefId",
- COUNT(declarations.id) as total_counter,
- COUNT(declarations.id) filter ( where EXTRACT(YEAR FROM AGE(cast("personalities"."birth_date" as date))) <=
- 5 ) as age_0_5_counter,
- COUNT(declarations.id)
- filter ( where EXTRACT(YEAR FROM AGE(cast("personalities"."birth_date" as date))) BETWEEN 6 AND 17 ) as age_6_17_counter,
- COUNT(declarations.id)
- filter ( where EXTRACT(YEAR FROM AGE(cast("personalities"."birth_date" as date))) BETWEEN 18 AND 39 ) as age_18_39_counter,
- COUNT(declarations.id)
- filter ( where EXTRACT(YEAR FROM AGE(cast("personalities"."birth_date" as date))) BETWEEN 40 AND 64 ) as age_40_64_counter,
- COUNT(declarations.id) filter ( where EXTRACT(YEAR FROM AGE(cast("personalities"."birth_date" as date))) >=
- 65 ) as age_65_final_counter
- FROM "dbo"."Employees"
- INNER JOIN "dbo"."Parties" ON "dbo"."Employees"."PartyId" = "dbo"."Parties"."Id"
- INNER JOIN "dbo"."Parties" "parties_dbo_Employees_join"
- ON "parties_dbo_Employees_join"."Id" = "dbo"."Employees"."PartyId"
- INNER JOIN "dbo"."LegalEntities" ON "dbo"."LegalEntities"."Id" = "parties_dbo_Employees_join"."LegalEntityId"
- INNER JOIN "declarations" ON "declarations"."employee_id" = "dbo"."Employees"."Id"
- INNER JOIN "personalities" ON "personalities"."id" = "declarations"."personality_id" AND
- "personalities"."type" = 'Patient::Person'
- INNER JOIN "user_patients" ON "user_patients"."personality_id" = "personalities"."id"
- INNER JOIN "declaration_statuses" ON "declaration_statuses"."id" = "declarations"."declaration_status_id"
- WHERE "dbo"."Parties"."LegalEntityId" = 867
- AND "dbo"."Employees"."EmployeeTypeRefValue" = 'DOCTOR'
- AND ("dbo"."Employees"."EmployeeStatusRefValue" = 'APPROVED')
- AND "declaration_statuses"."code" = 'ACTIVE'
- AND ("dbo"."LegalEntities"."Id" = 867)
- GROUP BY "dbo"."Employees"."Id", CONCAT_WS(' ', "dbo"."Parties"."LastName", "dbo"."Parties"."FirstName");
- ###################
- SELECT COUNT(DISTINCT "dbo"."Employees"."Id") as total_employee_counter,
- COUNT(DISTINCT "dbo"."Employees"."Id")
- filter ( where "dbo"."PositionRefs"."Value" = 'P7' ) as p7_position_counter,
- COUNT(DISTINCT "dbo"."Employees"."Id")
- filter ( where "dbo"."PositionRefs"."Value" = 'P8' ) as p8_position_counter,
- COUNT(DISTINCT "dbo"."Employees"."Id")
- filter ( where "dbo"."PositionRefs"."Value" = 'P9' ) as p9_position_counter,
- COUNT(DISTINCT "dbo"."Employees"."Id")
- filter ( where "dbo"."PositionRefs"."Value" = 'P10' ) as p10_position_counter,
- COUNT(DISTINCT "dbo"."Employees"."Id")
- filter ( where "dbo"."PositionRefs"."Value" = 'P11' ) as p11_position_counter,
- COUNT(declarations.id) as total_counter,
- COUNT(declarations.id) filter (where EXTRACT(YEAR FROM AGE(cast("personalities"."birth_date" as date))) <=
- 5 ) as age_0_5_counter,
- COUNT(declarations.id)
- filter ( where EXTRACT(YEAR FROM AGE(cast("personalities"."birth_date" as date))) BETWEEN 6 AND 17 ) as age_6_17_counter,
- COUNT(declarations.id)
- filter ( where EXTRACT(YEAR FROM AGE(cast("personalities"."birth_date" as date))) BETWEEN 18 AND 39 ) as age_18_39_counter,
- COUNT(declarations.id)
- filter ( where EXTRACT(YEAR FROM AGE(cast("personalities"."birth_date" as date))) BETWEEN 40 AND 64 ) as age_40_64_counter,
- COUNT(declarations.id) filter ( where EXTRACT(YEAR FROM AGE(cast("personalities"."birth_date" as date))) >=
- 65 ) as age_65_final_counter
- FROM "dbo"."Employees"
- INNER JOIN "dbo"."Parties" ON "dbo"."Employees"."PartyId" = "dbo"."Parties"."Id"
- INNER JOIN "dbo"."PositionRefs" ON "dbo"."PositionRefs"."Id" = "dbo"."Employees"."PositionRefId"
- INNER JOIN "dbo"."Parties" "parties_dbo_Employees_join"
- ON "parties_dbo_Employees_join"."Id" = "dbo"."Employees"."PartyId"
- INNER JOIN "dbo"."LegalEntities" ON "dbo"."LegalEntities"."Id" = "parties_dbo_Employees_join"."LegalEntityId"
- INNER JOIN "declarations" ON "declarations"."employee_id" = "dbo"."Employees"."Id"
- INNER JOIN "personalities" ON "personalities"."id" = "declarations"."personality_id" AND
- "personalities"."type" = 'Patient::Person'
- INNER JOIN "user_patients" ON "user_patients"."personality_id" = "personalities"."id"
- INNER JOIN "declaration_statuses" ON "declaration_statuses"."id" = "declarations"."declaration_status_id"
- WHERE "dbo"."Parties"."LegalEntityId" = 867
- AND "dbo"."Employees"."EmployeeTypeRefValue" = 'DOCTOR'
- AND ("dbo"."Employees"."EmployeeStatusRefValue" = 'APPROVED')
- AND "declaration_statuses"."code" = 'ACTIVE'
- AND ("dbo"."LegalEntities"."Id" = 867)
- GROUP BY "dbo"."LegalEntities"."Id";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement