select a=aa.a1/bb.a1,b=aa.b1/bb.b1,c=aa.c1/bb.c1
from
(select 1 as row,* from table where id = 1) aa,
(select 1 as row,* from table where id = 2) bb
where aa.row = bb.row
from
(select 1 as row,* from table where id = 1) aa,
(select 1 as row,* from table where id = 2) bb
where aa.row = bb.row
解决方案 »
- SOS!! SQL SERVER 误操作了UPDATE,如何复原?
- (新手求助)数据库的更新
- 求一个好算法或办法!
- 请求几个MSSQL的查询问题,希望前辈们指点。
- sql与execl问题(急)
- SQL SERVER2005安装后的是否为强密码设置在那里修改
- 请问各位高手,Access2000数据库有50个表,每个表有100000条记录会怎样,我想将Sql Server中的数据背份到Access表中如何,因为用delphi ado 不能从事实上将sql server 从服务器端备份到客户端。
- 请问哪里有SQLSERVER2000下载?回者有分。
- ORACLE初学者的一个非常简单的问题
- 1000万数据,用自增id做条件,sum某个字段很快,用time做条件sum某个字段就很慢
- 模糊查询问题 查字母快 查数字很慢
- 联合查询与连接查询区别
insert into @table1 select 1,65,59,92
insert into @table1 select 2,38,42,63declare @table2 table(a varchar(10),b varchar(10),c varchar(10))
insert into @table2
select
rtrim(cast(b.a1*100.0/a.a1 as numeric(8,2)))+'%',
rtrim(cast(b.b1*100.0/a.b1 as numeric(8,2)))+'%',
rtrim(cast(b.c1*100.0/a.c1 as numeric(8,2)))+'%'
from
@table1 a,@table1 b
where
a.id=1 and b.id=2select * from @table2/*
a b c
---------- ---------- ----------
58.46% 71.19% 68.48%
*/
=========
當然有很多記錄,不過是不同年份的記錄,還有一個字段是存放年份的我沒寫出來,加上年份條件出來的就只有兩條記錄,a1,b1,c1...就是1月份,2月份,3月份....12月份.等我測試上面朋友給的語句先
insert into @table1 select 1,65,59,92
insert into @table1 select 2,38,42,63declare @table2 table(a money,b money,c money)
insert into @table2
select
round(convert(money,b.a1)/a.a1*100,2),
round(convert(money,b.b1)/a.b1*100,2),
round(convert(money,b.c1)/a.c1*100,2)
from
(select * from @table1 where id = 1) a,
(select * from @table1 where id = 2) b
select * from @table2
select
cast(b.a1*100.0/a.a1 as numeric(8,2))+'%',
cast(b.b1*100.0/a.b1 as numeric(8,2))+'%',
cast(b.c1*100.0/a.c1 as numeric(8,2))+'%'
from
table1 a,table1 b
where
a.id=1 and b.id=2
老是提示運算式出錯,
用convert會出錯:運算式中未定義的 'convert' 函數。改成下面就成功了,
rtrim(Round((b.month1/a.month1*100),2))+'%'謝謝,結帖