日期:2014-05-18  浏览次数:20483 次

能否有这样的查询?
价钱表price
字段有type,firstprice,secondprice

数据表datatable
字段有type,sfzh(身份证),firstorsecond

两个表通过type相连,其中字段firstorsecond的值为first或者second,若为first则价钱为字段firstprice,若为second则价钱为字段secondprice




------解决方案--------------------
SQL code

select a.[type],a.sfzh,
case a.firstorsecond when 'first' then firstprice else secondprice end as firstorsecond
 from datatable  a inner join price b
on a1.[type]=B2.[type]