读书人

联合查询定位有关问题

发布时间: 2013-03-13 10:56:58 作者: rapoo

联合查询定位问题

[解决办法]
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)

读书人网 >SQL Server

热点推荐