select sum(je)from (select top 10 je from tb_table1 where kmdm='1511')a
-
select sum(je)from (select top 10 je from tb_table2 where kmdm='1516')b--?
-
select sum(je)from (select top 10 je from tb_table2 where kmdm='1516')b--?
(select top 10 je from tb_table2 where kmdm='1516'))select a.je - b.je
from
(
select je,ROW_NUMBER() over(order by getdate()) rownum
from tb_table1
where kmdm='1511'
)a
inner join
(
select je,ROW_NUMBER() over(order by getdate()) rownum
from tb_table2
where kmdm='1516'
)b
on a.rownum = b.rownum
where a.rownum = 10 and b.rownum = 10
union all
select * from t2
--会把第一个查询和第二个查询的结果集合并select * from t1
union
select * from t2
--合并两个查询的结果集,并且去掉重复的数据(重复只取一行)
from
(
select je,ROW_NUMBER() over(order by getdate()) rownum
from tb_table1
where kmdm='1511'
)a
inner join
(
select je,ROW_NUMBER() over(order by getdate()) rownum
from tb_table2
where kmdm='1516'
)b
on a.rownum = b.rownum
where a.rownum = 10 and b.rownum = 10
select sum(je)from (select top 10 je from tb_table2 where kmdm='1516')b
ROW_NUMBER()不是可识别的函数名?
from
(
select je,ROW_NUMBER() over(order by getdate()) rownum
from tb_table1
where kmdm='1511'
)a
inner join
(
select je,ROW_NUMBER() over(order by getdate()) rownum
from tb_table2
where kmdm='1516'
)b
on a.rownum = b.rownum
where a.rownum = 10 and b.rownum = 10
ROW_NUMBER()不是可识别的函数名?哦,你用的是2000对吧,我改了一下,适合2000的,你试试:
if OBJECT_ID('tempdb..#t1') is not null
drop table #t1
if OBJECT_ID('tempdb..#t2') is not null
drop table #t2select je,IDENTITY(int,1,1) rownum into #t1
from tb_table1
where kmdm='1511'select je,IDENTITY(int,1,1) rownum into #t2
from tb_table2
where kmdm='1516'
select a.je - b.je
from #t1 a
inner join #t2 b
on a.rownum = b.rownum
where a.rownum = 10 and b.rownum = 10
from
(
select je,ROW_NUMBER() over(order by getdate()) rownum
from tb_table1
where kmdm='1511'
)a
inner join
(
select je,ROW_NUMBER() over(order by getdate()) rownum
from tb_table2
where kmdm='1516'
)b
on a.rownum = b.rownum
where a.rownum = 10 and b.rownum = 10
不对的减出来的 都是0
from
(
select je,ROW_NUMBER() over(order by getdate()) rownum
from tb_table1
where kmdm='1511'
)a
inner join
(
select je,ROW_NUMBER() over(order by getdate()) rownum
from tb_table2
where kmdm='1516'
)b
on a.rownum = b.rownum
where a.rownum = 10 and b.rownum = 10
不对的减出来的 都是0哦 你有具体的数据不
ROW_NUMBER()不是可识别的函数名?哦,你用的是2000对吧,我改了一下,适合2000的,你试试:
if OBJECT_ID('tempdb..#t1') is not null
drop table #t1
if OBJECT_ID('tempdb..#t2') is not null
drop table #t2select je,IDENTITY(int,1,1) rownum into #t1
from tb_table1
where kmdm='1511'select je,IDENTITY(int,1,1) rownum into #t2
from tb_table2
where kmdm='1516'
select a.je - b.je
from #t1 a
inner join #t2 b
on a.rownum = b.rownum
where a.rownum = 10 and b.rownum = 10
不对的减出来的 都是0
ROW_NUMBER()不是可识别的函数名?哦,你用的是2000对吧,我改了一下,适合2000的,你试试:
if OBJECT_ID('tempdb..#t1') is not null
drop table #t1
if OBJECT_ID('tempdb..#t2') is not null
drop table #t2select je,IDENTITY(int,1,1) rownum into #t1
from tb_table1
where kmdm='1511'select je,IDENTITY(int,1,1) rownum into #t2
from tb_table2
where kmdm='1516'
select a.je - b.je
from #t1 a
inner join #t2 b
on a.rownum = b.rownum
where a.rownum = 10 and b.rownum = 10
不对的减出来的 都是0 或者你有QQ吗,方便的话,帮你看看
table1表的前十条数据减去table2表的前十条数据 比如table1表第一条数据减去table2表的第一条数据,以此类推