还是SQL语句问题
有两张表,如下:
表A
Id Num1 Num2
1 w 2
2 s 3
3 x 5
4 t 7
表B
ID Num3 Num4
1 w 4
2 s 3
3 x 15
4 t 10
我想得到如下结果:
表C
ID Num1 Num2 Num4 Num5
1 w 2 4 50%
2 s 3 3 100%
3 x 5 15 33.334%
4 t 7 10 70%
请问该用哪个函数,如何用.谢谢了!
------解决方案--------------------select A.ID,A.Num1,A.Num2,B.Num4,str(1.0*A.Num2/B.Num4*100,10,3)+ '% '
from A,B
where A.Num1=B.Num3
------解决方案--------------------select a.*,isnull(cast(cast(a.Num4/b.Num4*100 as dec(18,3))as varchar(10)), '100 ')+ '% '[Num5] into c from a left join b on b.id=a.id
------解决方案--------------------select A.ID,A.Num1,A.Num2,B.Num4,str(cast(A.Num2 as decimal)/B.Num4*100,10,2)+ '% '
from A inner join B on A.Num1=B.Num3
------解决方案--------------------select a.*,str(a.num2/b.num4*100,10,3)+ '% ' from a,b where a.id=b.id