If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Min/max problem - Need help

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-24-11, 08:53
DaKlonker DaKlonker is offline
Registered User
 
Join Date: Nov 2011
Posts: 5
Min/max problem - Need help

Hi,
I have a problem related to the function min and max. In this case Im working with 5 tables with this relation:

1. Customer(Name, address, KNR(PK)
2. Belong(KNR(FK), BENR(FK)
3. Order(order_sum, BENR(PK)
4. IN_Order(price, order_amount, order_date, BENR(FK), BANR(FK)
5. Product (Product_name, product_price, BANR(PK)

I want to answar this question:

- Which customer(s) (show the customer(s), have the highest order sum and which have the lowest order sum. I should also show the product in the order.


If I have been unclear so feel free to ask

thanks in advance!

/Martin
Reply With Quote
  #2 (permalink)  
Old 11-24-11, 09:06
healdem healdem is online now
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,250
what have you tried so far?
where has that gone wrong?
what steps did you take to see if you could resolve the problem?
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #3 (permalink)  
Old 11-24-11, 10:11
DaKlonker DaKlonker is offline
Registered User
 
Join Date: Nov 2011
Posts: 5
reply:::

My code:

Select name, order_sum, product_name from customer c, belong b, order o, in_order i, product p WHERE order_sum=(select min(order_sum), max(order_sum) from order) AND p.banr=i.banr AND i.benr=o.benr AND o.benr=b.benr AND b.knr=c.knr;

The result of the code above:
- operand should contain i column(s)

When I only use max() function i get the right result of max.
How should I use both max and min function in the code?
Reply With Quote
  #4 (permalink)  
Old 11-25-11, 07:09
it-iss.com it-iss.com is offline
Registered User
 
Join Date: Sep 2009
Location: San Sebastian, Spain
Posts: 620
Try the following:

Select name, order_sum, product_name
from customer c,
belong b,
order o,
in_order i,
product p,
(select min(order_sum) minsum, max(order_sum) maxsum FROM order) x
WHERE (order_sum = x.minsum OR order_sum = x.maxsum)
AND p.banr=i.banr
AND i.benr=o.benr
AND o.benr=b.benr
AND b.knr=c.knr;
__________________
Ronan Cashell
Senior Oracle/MySQL DBA
http://www.it-iss.com
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On