当前位置: 代码迷 >> Sql Server >> 能否有这样的查询?解决思路
  详细解决方案

能否有这样的查询?解决思路

热度:26   发布时间:2016-04-27 12:59:20.0
能否有这样的查询?
价钱表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 bon a1.[type]=B2.[type]
  相关解决方案