postgresql - SQL dynamic group by varying number of columns -


I need to change the clause rule dynamically by group for grouping. I always return the same number and column names is.

For example in the table:

  CREATE TABLE employee (employee_ID number no.l.l, department_id integer, changing status character (50), / * active / idle * / value Numeric, Revenue (Numerical), First_name Characters Variant (50), Last_Name Characters Separate (50))   

I need to do some queries like this:

How do I run this query?

It depends, what you want to achieve: you not only on the column You can use GROUP BY .

If you want to isolate the disabled employees and use the following types of employees from each other to each other:

  - ... group In the case of case when = 'active' then the department_id when the position = 'idle' then the tap end, employee_id   

but the above solution will deposit passive staff with all those other employees Which departments do not specify If ( department_id IS NULL ). If you do not have any worries, then this is the simplest solution.

You can also use it:

  - ... in case case by the group = 'active' then ro (department_id, employee_id) WHEN condition = 'inactive Then ROO (employee_id) ED   

but keep in mind how it works.

Note : When you use employee_id in GROUP BY , then COUNT (employee_id) < / Code> will always be 1 .

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -