Home > database >  Have a great god know how to optimize the SQL
Have a great god know how to optimize the SQL

Time:09-24

SELECT
Months probation period, the following year, one to two years, two to three years, three to five years, five to ten years, ten to twenty years, twenty years
The FROM
(
SELECT DISTINCT
(
SELECT
DISTINCT
Extract (the month from per_all_people_f. Effective_start_date)
The FROM
Per_all_people_f
WHERE
Extract (the month from per_all_people_f. Effective_start_date)=extract (the month from to_date (' 2017-01-31 ', '- dd yyyy - mm))

) in the as,

(SELECT DISTINCT
Count (*)
The FROM
Per_all_people_f p1
LEFT the JOIN per_all_assignments_f p2 ON p1. Person_id=p2. The person_id
LEFT the JOIN per_contracts_f p3 ON p3. Person_id=p1. Person_id
WHERE
P1. Attribute1 is NOT NULL
AND ((to_date (p3. Practice_end_time '- dd yyyy - mm) - to_date (' 2017-01-31', '- dd yyyy - mm)) & gt; 0)
AND p1. Effective_end_date is NULL
AND (p2 assignment_status_type_id!=3 OR p2. Assignment_status_type_id isnull)
AND CURRENT_DATE BETWEEN p2. Effective_start_date AND COALESCE (
The p2 effective_end_date,
To_date (' 2999-12-31 ', '- dd yyyy - MM)
='1') and primary_flag
AND
P1. Effective_end_date ISNULL - on-the-job
AND
P1. Attribute1 is not null -- -- to work time not empty

) as probation period,
(
SELECT COUNT ((

(extract (year from (the age (to_date (' 2017-01-31 ', '- dd yyyy - mm), to_date (p1) attribute1,' yyyy - mm - dd)))))
<1) the or NULL)
The FROM
Per_all_people_f p1
LEFT the JOIN per_all_assignments_f p2 ON p1. Person_id=p2. The person_id
LEFT the JOIN per_contracts_f p3 ON p1. Person_id=p3. Person_id
WHERE
P1. Effective_end_date ISNULL - on-the-job
AND
(
(p3. Practice_end_time is null
The or p3. Practice_end_time=' ')
Or
To_date (p3) practice_end_time, '- dd yyyy - mm) & lt;=to_date (' 2017-01-31 ', '- dd yyyy - mm)) - screening after probation period or the end of the probation period time is empty
AND
P1. Attribute1 is not null -- -- to work time not empty
AND
(p2. Assignment_status_type_id!=3 or
P2. Assignment_status_type_id isNULL - not retired
AND CURRENT_DATE BETWEEN p2. Effective_start_date AND COALESCE (
The p2 effective_end_date,
To_date (' 2999-12-31 ', '- dd yyyy - MM)
='1') and primary_flag
) as the following year,

(
SELECT COUNT ((
(extract (year from (the age (to_date (' 2017-01-31 ', '- dd yyyy - mm), to_date (p1) attribute1,' yyyy - mm - dd)))))
=1) or NULL)
The FROM
Per_all_people_f p1
LEFT the JOIN per_all_assignments_f p2 ON p1. Person_id=p2. The person_id
LEFT the JOIN per_contracts_f p3 ON p1. Person_id=p3. Person_id
WHERE
P1. Effective_end_date ISNULL - on-the-job
AND
(
(p3. Practice_end_time is null
The or p3. Practice_end_time=' ')
Or
To_date (p3) practice_end_time, '- dd yyyy - mm) & lt;=to_date (' 2017-01-31 ', '- dd yyyy - mm)) - screening after probation period or the end of the probation period time is empty
AND
P1. Attribute1 is not null -- -- to work time not empty
AND
(p2. Assignment_status_type_id!=3 or
P2. Assignment_status_type_id isNULL - not retired
AND CURRENT_DATE BETWEEN p2. Effective_start_date AND COALESCE (
The p2 effective_end_date,
To_date (' 2999-12-31 ', '- dd yyyy - MM)
='1') and primary_flag
) as one to two years,

(
SELECT COUNT ((
(extract (year from (the age (to_date (' 2017-01-31 ', '- dd yyyy - mm), to_date (p1) attribute1,' yyyy - mm - dd)))))
=2) or NULL)
The FROM
Per_all_people_f p1
LEFT the JOIN per_all_assignments_f p2 ON p1. Person_id=p2. The person_id
LEFT the JOIN per_contracts_f p3 ON p1. Person_id=p3. Person_id
WHERE
P1. Effective_end_date ISNULL - on-the-job
AND
(
(p3. Practice_end_time is null
The or p3. Practice_end_time=' ')
Or
To_date (p3) practice_end_time, '- dd yyyy - mm) & lt;=to_date (' 2017-01-31 ', '- dd yyyy - mm)) - screening after probation period or the end of the probation period time is empty
AND
P1. Attribute1 is not null -- -- to work time not empty
AND
(p2. Assignment_status_type_id!=3 or
P2. Assignment_status_type_id isNULL - not retired
AND CURRENT_DATE BETWEEN p2. Effective_start_date AND COALESCE (
The p2 effective_end_date,
To_date (' 2999-12-31 ', '- dd yyyy - MM)
='1') and primary_flag
) as two to three years,

(
SELECT COUNT ((
(extract (year from (the age (to_date (' 2017-01-31 ', '- dd yyyy - mm), to_date (p1) attribute1,' yyyy - mm - dd)))))
Between 3 and 4) or NULL)
The FROM
Per_all_people_f p1
LEFT the JOIN per_all_assignments_f p2 ON p1. Person_id=p2. The person_id
LEFT the JOIN per_contracts_f p3 ON p1. Person_id=p3. Person_id
WHERE
P1. Effective_end_date ISNULL - on-the-job
AND
(
(p3. Practice_end_time is null
The or p3. Practice_end_time=' ')
Or
To_date (p3) practice_end_time, '- dd yyyy - mm) & lt;=to_date (' 2017-01-31 ', '- dd yyyy - mm)) - screening after probation period or the end of the probation period time is empty
AND
P1. Attribute1 is not null -- -- to work time not empty
AND
(p2. Assignment_status_type_id!=3 or
P2. Assignment_status_type_id isNULL - not retired
AND CURRENT_DATE BETWEEN p2. Effective_start_date AND COALESCE (
The p2 effective_end_date,
To_date (' 2999-12-31 ', '- dd yyyy - MM)
='1') and primary_flag
) as three to five years,
(
SELECT COUNT ((
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related