读书人

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

发布时间: 2012-05-08 22:09:41 作者: rapoo

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

读书人网 >SQL Server

热点推荐