首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

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

2012-05-08 
能否有这样的查询?价钱表price字段有type,firstprice,secondprice数据表datatable字段有type,sfzh(身份证)

能否有这样的查询?
价钱表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] 

热点排行