sql - Different prices per state for product -


i trying run query price of item purchased customer. issue products built @ base level 'blank' state example see below.

state product price         x       5.00 oh      x       5.25  ca      x       5.75         y       6.00 

i know if im getting somewhere type of case statement , place this going join statement

(case when a.state= b.state a.state else 'blank' end) 

edit:

select o.name, o.state, o.item, i.rate orders o left join on item_desc o.item = i.item , case         when o.state = i.state         o.state        else null        end = i.state 

revised works null isnt working need replace catch blank field (field empty/blank not null)

in case rate null, can result doing correlated sub query in case statement.

sql fiddle demo

select o.name,        o.state,         o.item,         case when i.rate null              ( select rate item_desc                     item = o.item                    , coalesce(state,'') =''                   )             else i.rate             end rate orders o left join item_desc on o.item = i.item , o.state = i.state 

Comments

Popular posts from this blog

javascript - How to synchronize the Three.js and HTML/SVG coordinate systems (especially w.r.t. the y-axis)? -

javascript - How do I find how many occurences are there of a highlighted string, and which occurence is it? -

java - Reading data from multiple zip files and combining them to one -