Help modifying query to honor min and max markups

I need modify this query to honor the minmk and maxmk, if mt = 'P' and either minmk and maxmk exist.
Not sure how to do that...

Currently, the query returns 125.00 for the first record and 2893.75. It needs to return 140.00 and 2815.00

Note: There are only 'P' (percentage) and 'F' (flat) markup types.

    -- when the markup is a 'P' (percentage) multiply     
               FROM p.markups c0 
               WHERE = 'M07' AND 
            = 'M34' AND 
            = '107') = 'P' THEN
		TO_CHAR(u.price + (u.price * (SELECT 
		                                FROM p.markups c1 
		                                WHERE = 'M07' AND 
		                             = 'M34' AND 
		                             = '107')) , 'FM999999999.00')
	-- when the markup is a 'F" (flat), so add it
		TO_CHAR(u.price + (SELECT 
		                    FROM p.markups c2 
		                    WHERE = 'M07' AND 
		                 = 'M34' AND 
		                 = '107') , 'FM999999999.00')
	END as mkprice	
FROM u.unet u
WHERE = 'M34' AND = '107'

Open in new window

If I have this data in `p.markups`:
"id" , "pid", "pt" , "mt", "mk", "minmk", "maxmk", "exc"
"M07", "M34", "107", "P" , 0.25, 40     , 500    , 0

Open in new window

and this data in u.unet:
"id",  "pt" , "price"
"M34", "107",  100.00
"M34", "107", 2315.00

Open in new window

LVL 27
Eddie ShipmanAll-around developerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jan LouwerensSoftware EngineerCommented:
   CASE WHEN ( = 'P') THEN  u.price + LEAST(GREATEST((u.price *, p.minmk), p.maxmk)
        ELSE /* ( = 'F') */ u.price + LEAST(GREATEST(, p.minmk), p.maxmk)
        END AS mkprice
   u.unet u, p.markups p

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Eddie ShipmanAll-around developerAuthor Commented:
With some modification this worked just great, thanks.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.