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

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -