sql - group by problem -


SQL Group with problem

I have a SQL group with the problem. In my table there are the following form:

  Cust_id Value_id value ---------------------------- 1. 556. 5000. -------------- - ------------- 2. 654. 600. 2. 432. 487.2 2. 546. 500. ----------------- - -------- 3. 455. 200. 3.877. 143. 3. 123. 879.  

Now when I run this query:

  select cust_id as max, select maximum (value), min (value) as the minimum number of group by cust_id  

I'm getting

  CUST_ID MAX Min. 1. 5000. 2. 600. 487. 3. 879. 143.  

But I really want that there is no maximum and minimum price, but the value associated with the price_ID
will result in

  tight_id max Min. 1. 556. 556. 2. 654. 432. 3. 123. 877.  

I am in a disadvantage for how to do this, I think the above question is of some kind The sub query will be, but this far as far as I have found

Use:

  SELECT x.cust_id, y.price_id AS max, from z.price_id minimum (SELECT t.cust_id, MAX (t.price) as max, MIN (T.Prices) from minimum T. T. T. Group T. cust_id) x LEFT JOIN TABLE y y.cust_id = X.cust_id and y.price = x.max LEFT JOIN tables on z.cust_id = x.cust_id and z.price = x.min  

The problem is that if Custom_ID has two high records that with higher (or lower) price, you will see duplicates and logic to deal with relationships Radaan need to.


Comments