1
1
132bpm2017-03-16 23:28:44
Oracle
132bpm, 2017-03-16 23:28:44

How to remove a field from Group by?

Hello,
there is a question on request, the request is as follows:

select 
           decode (ep.ext_brand, ' ', 'PR',
                                      'YR') brand,
           case
           when ep.type_op < 30 then 'VPM' else 'VAD' end flow,
           'RU',
           lp.id_produit, 
           sum(lp.qte_a_preparer)
from 
           entete_op ep, 
           ligne_op lp,
           entete_op_client epc
where 
           ep.id_op = lp.id_op and
           ep.id_op = epc.id_op and
           ep.etat < 2000
group by ep.ext_brand, lp.id_produit, ep.type_op

The question is:
The ep.type_op field has multiple values, and I only need two. I use the CASE statement, but at the same time ORACLE forces grouping by ep.type_op, then there is no point in the CASE statement, because the result separates 2 rows with the same flow values.
example result using ep.type_op:
YR VPM RU AA535 1
YR VPM RU AA535 1
example result without using ep.type_op :
YR RU AA535 2
Here I need the result as in the second query, only using the ep.type_op field...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
d-stream, 2017-03-17
@132bpm

the same case as in the select may well live in group by, more precisely, it probably cannot, but must

K
Konstantin Tsvetkov, 2017-03-17
@tsklab

The ep.type_op field has multiple values, and I only need two.

Specifies a search condition for a group or an aggregate. HAVING can be used only with the SELECT statement. HAVING is typically used in a GROUP BY clause. When GROUP BY is not used, HAVING behaves like a WHERE clause.
I need to get a parameter if less than 30 then 'value 1' otherwise 'value 2' -> what I described using CASE in the select.
Add a calculated field to the table or make a view.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question