oracle - sql HR schema making a line appear once -
i struggling time thought best use hr schema show example:
the following sql:
select department, sum(salary) "money", case when job_id = 'sa_man' 'y' end "indicator" (select first_name || ' ' || last_name "name", salary, job_id, department_id depatment employees) group depatment, case when job_id = 'sa_man' 'y' end order 1 ;
from sql, have department 80 appearing twice has sa_man 'y' , null.
my question how have appearing once looking @ whether sa_man there without appearing twice.
with minor modification: don't group case
. make max on in select clause.
select department, sum(salary) "money", max(case when job_id = 'sa_man' 'y' end) "indicator" (select first_name || ' ' || last_name "name", salary, job_id, department_id department employees) group department order 1;
edit: if want indicator,
max(case when condition 'n/a' end) "indicator"
but if want multiple indicators, can't in same column(nobody can't simple datatype). solution add more columns:
select department, sum(salary) "money", max(case when job_id = 'sa_man' 'y' end) "indicatory" max(case when condition 'n' end) "indicatorn" max(case when anothercondition 'n/a' end) "indicatorna" (select first_name || ' ' || last_name "name", salary, job_id, department_id department employees) group department order 1;
the columns meaning: 'for department exists employee n or y or na, respectively'.
Comments
Post a Comment