用一条sql语句得出A和B的剩余数量
数据库 用一条sql语句得到两个表中数据的统计
答案:2 悬赏:0 手机版
解决时间 2021-02-28 04:16
- 提问者网友:呐年旧曙光
- 2021-02-27 05:43
最佳答案
- 五星知识达人网友:你可爱的野爹
- 2021-02-27 05:51
select a.name,a.buy-b.sell as left
from
(
select name,sum(buy) as buy
from tableA
where name in ('A','B')
group by name
) a
left outer join
(
select name,sum(sell) as sell
from tableB
where name in ('A','B')
group by name
) b
on a.name = b.name
from
(
select name,sum(buy) as buy
from tableA
where name in ('A','B')
group by name
) a
left outer join
(
select name,sum(sell) as sell
from tableB
where name in ('A','B')
group by name
) b
on a.name = b.name
全部回答
- 1楼网友:酒安江南
- 2021-02-27 06:00
create procedure sp_deletealldata
as
exec sp_msforeachtable 'alter table ? nocheck constraint all'
exec sp_msforeachtable 'alter table ? disable trigger all'
exec sp_msforeachtable 'delete from ?'
exec sp_msforeachtable 'alter table ? check constraint all'
exec sp_msforeachtable 'alter table ? enable trigger all'
exec sp_msforeachtable 'select * from ?'
gosp_deletealldata这个脚本创建了一个命名为sp_deletealldata的存储过程,前面两行语句分别禁用约束和触发器,第三条语句才是真正地删除所有数据,接下里的语句分别还原约束和触发器,最后一条语句是显示每个表中的记录,当然这条语句也可以不要,我只是想确认一下是否清空了所有表而已。
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯