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

联合查询定位有关问题

2013-03-13 
联合查询定位问题[解决办法]select (case when t1.pid 1 then t2.p1 when t1.pid 2 then t2.p2 when t

联合查询定位问题

[解决办法]
select (case when t1.pid = 1 then t2.p1 when t1.pid = 2 then t2.p2 when t1.pid = 3 then t2.p3 end) as p from tablepos t1 join tableprice t2 on t1.trid = t2.id;
[解决办法]
mysql> select (case when t1.pid = 1 then t2.p1 when t1.pid = 2 then t2.p2 when t
1.pid = 3 then t2.p3 end) as p from tablepos t1 join tableprice t2 on t1.trid =
t2.id;
+------+

[解决办法]
 p    
[解决办法]

+------+

[解决办法]
   19 
[解决办法]

+------+
1 row in set (0.00 sec)
[解决办法]
如果只有p1p2p3用2楼方法吧,不定个数需要动态

declare @sql varchar(max)
select @sql = 'select P' + cast(PID as varchar) + ' from 价格表 where id = ' + cast(TRID as varchar)
from 定位表
where ID = 99

exec(@sql)

热点排行