asp.nt中
我这里有两个表:
入库表A:
it_id it_qty(数量)
1 50
2 70出库表B ot_id ot_qty(数量) it_id
001 40 1
002 20 2
怎么把表A与表B相连之后每一行的入库数量(it_qty)减去出库数量(ot_qty),显示剩余数量
如果剩余数量为0,则这一条数据不会显示出来。用GridView绑定出来。求各位帮帮忙啊
我这里有两个表:
入库表A:
it_id it_qty(数量)
1 50
2 70出库表B ot_id ot_qty(数量) it_id
001 40 1
002 20 2
怎么把表A与表B相连之后每一行的入库数量(it_qty)减去出库数量(ot_qty),显示剩余数量
如果剩余数量为0,则这一条数据不会显示出来。用GridView绑定出来。求各位帮帮忙啊
解决方案 »
- 关于动态生成GridView并设置其样式
- |M| 数据绑定时不绑定某条件的行要怎么办
- WIN2003改Windows权限后,.net网站均出现"Server Error in '/' Application"
- Session为什么会莫名其妙地丢失?
- 我想在web页面上使用crystalreportview 来查看水晶报表,都没有问题了但是没有看到“打印“按钮
- 在DataGrid中做排序,我的数据绑定是一个对象里面的属性,而我的表达式也是一个属性,这样做对吗?如果对的,那为什么页眉上的Button文字
- jquery在.net中如何实现跨域的ajax请求
- 请问Rational XDE的注册号是什么?急!!!
- 用户注册控件或登录控件与数据库连接的问题?
- position:absolute的奇怪问题
- gridview更新问题求助
- 关于aspnetpager的问题
it_id int,
it_qty int
)
insert into #A select 1,50
insert into #A select 2,70create table #B
(
ot_id nchar(10),
ot_qty int,
it_id int
)
insert into #B select '001',40,1
insert into #B select '002',20,2select b.it_id,(A.it_qty-B.ot_qty) '剩余的'
from #A A join #B B
on A.it_id=b.it_idit_id 剩余的
----------- -----------
1 10
2 50
from a inner join b on a.it_id=b.it_id order by a.it_id;
然后按正常代码执行,绑定到GRIDVIEW就可以了
declare @t table( it_id int , it_qty int )
insert into @t values( 1 , 50 )
insert into @t values( 2 , 70 )
declare @t1 table( ot_id int , ot_qty int , it_id int )
insert into @t1 values(001 , 40 , 1 )
insert into @t1 values(002 , 20 , 2 )
select a.it_id , min(a.it_qty) -SUM(b.ot_qty) as qty from @t a
inner join @t1 b on b.it_id = a.it_id
group by a.it_id
having( min(a.it_qty) -SUM(b.ot_qty) >0)
select a.it_id,mim(a.it_qty)-SUM(b.ot_qty) as '剩余的' from a inner join b
on a.it_id =b.it_id
group by a.it_id
having (MIN(a.it_qty)-SUM(b.ot_qty)>0)
from
(
select tab_1.*,t1.it_qty
from
(
select t2.it_id,sum(t2.ot_qty)as ot_qty
from Table_2 t2
group by t2.it_id
)as tab_1,Table_1 t1
where tab_1.it_id=t1.it_id
)as tab_2
where tab_2.it_id=tab_2.it_id and tab_2.it_qty>tab_2.ot_qty
select tab_2.*,(tab_2.it_qty-tab_2.ot_qty)as qty
from
(
select tab_1.*,t1.it_qty
from
(
select t2.it_id,sum(t2.ot_qty)as ot_qty
from Table_2 t2
group by t2.it_id
)as tab_1,Table_1 t1
where tab_1.it_id=t1.it_id
)as tab_2
where tab_2.it_id=tab_2.it_id and tab_2.it_qty>tab_2.ot_qty
group by TabInstore_Total.it_batch
having (min( TabInstore_Total.it_qty)-SUM( TabOutstore_Total.ot_qty))>0它的提示“on”附近有语法错误啊
tab_2.it_qty-tab_2.ot_qty ????
“it_qty ” 和 “ot_qty ” 它们不在同一个表里啊