⑴ sql中三个表的数据相加减的语句是什么
select distinct table1.编号, (table1.数量1+table2.数量2 - table3.数量3) as jg from table1,table2,table3 where table1.编号 = table2.编号 and table2.编号 = table3.编号
⑵ 在SQL中怎样实现加减运算
首先,进行mysql命令行
点开始/运行,输入cmd。
使用cd命令进入mysql所在文件夹。
执行mysql
-u
-t
即mysql
-u
用户名
-t
密码。
如果root用户密码为空,直接键入:
mysql
-u
root
回车即可。
进入mysql命令行后,输入:
seledt
3+2;
回车,即可显示结果为5.
如下所示:
mysql>
select
3+2;
+-----+
|
3+2
|
+-----+
|
5
|
+-----+
1
row
in
set
(0.00
sec)
mysql>
⑶ SQL语句中两个表如何减(关联)请求帮助
给你个参考答案
SELECT aa.T,aa.s-temp.s as '剩余 s' FROM (SELECT T,SUM(S) AS S FROM BB GROUP BY T) as temp,aa where temp.t=aa.t
⑷ sql 多表 计算列 加减计算
select sum(cast(单件总价 as float)) + sum(cast(返修收费 as float))+ sum(cast(运费 as float)) +sum(-cast(总价 as float))
from 批发信息,返修信息 ,运费信息,退货信息,
where 批发信息.客户名=返修信息.客户名 and 返修信息.客户名=运费信息.客户名 and 运费信息.客户名=退货信息.客户名
and 批发信息.客户名='xx'
⑸ SQL 语句 如何在三个表中的某项数据进行减法运算
前提是他们必须有一个关联的键。
如:
select A.*, ( (select 采购数量 from B where B.id =A.id)-(select 消耗数量 from C where C.id =A.id)) as 库存量 from A
有问题可以追问
⑹ sql数据库两表关联查询,并根据一张表的固定条件下两列相减并合计
sql运行结果
⑺ SQL中使用触发器实现两张表之间的加减问题
create table TEST_A
( NO CHAR(2) NOT NULL ,
QTY [numeric](6, 2) NULL )
-- drop table TEST_B
create table TEST_B
( NO CHAR(2) NOT NULL ,
NO2 CHAR(2) NOT NULL ,
QTY [numeric](6, 2) NULL )
INSERT TEST_B VALUES('1','2',5)
select * from TEST_B
select * from TEST_a
delete from TEST_B
delete from TEST_a
update d set d.qty = d.qty - 1 from TEST_b d where d.NO2 = '2'
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
alter trigger [dbo].[tr_TEST_B_i] on [dbo].[TEST_B] for insert,delete as
set nocount on
if object_id('tempdb..#disable_TEST_B') is not null return
begin tran
if exists(select 1 from inserted a , TEST_A b where a.no = b.no)
update b set b.qty = isnull(b.qty,0) + a.qty from inserted a ,TEST_A b where a.no = b.no
if @@error <> 0
begin
rollback
raiserror('update error!',16,1)
return
end
if exists(select 1 from deleted a , TEST_A b where a.no = b.no)
update b set b.qty = b.qty - a.qty from deleted a ,TEST_A b where a.no = b.no
if @@error <> 0
begin
rollback
raiserror('delete error!',16,1)
return
end
INSERT TEST_A (no,qty) select a.no,a.qty from inserted a where not exists(select 1 from TEST_A b where a.no = b.no)
if @@error <> 0
begin
rollback
raiserror('insert error!',16,1)
return
end
commit
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
alter trigger [dbo].[tr_TEST_B_u] on [dbo].[TEST_B] for update as
set nocount on
if object_id('tempdb..#disable_TEST_B') is not null return
if update(no)
begin
rollback
raiserror('buneng xiugai no!',16,1)
return
end
IF(Update(qty))
begin
DECLARE @SL decimal(6,2) --修改前数量
DECLARE @DHSL decimal(6,2) --修改后数量
declare @no char(2)
DECLARE @upSL decimal(6,2)
SELECT @no = no ,@SL=qty FROM Deleted
SELECT @DHSL=qty FROM INSERTED
set @upSL = @DHSL - @SL
begin tran
update b set b.qty = isnull(b.qty,0) + @upSL from TEST_A b where b.no = @no
if @@error <> 0
begin
rollback
raiserror('update error!',16,1)
return
end
commit
end
⑻ SQL统计查询同一个表中的记录,然后减法运算,麻烦您了!!!
类型与金额都为 数字
access:
select sum(金额) -(select sum(金额) from 表 where 类型=1) from 表 where 类型=2
sql2000:
select (sum(case 类型 when 2 then 金额 else 0 end))-(sum(case 类型 when 1 then 金额 else 0 end)) from 表
⑼ 在SQL中 两个表的数据怎么相减
说清楚一点:是两个视图中的元组相减还是两个视图中连接后的数据结果相减?
一个关系减一个关系可以用谓词NOT IN或条件 <> ANY进行关系操作运算。
两个关系中的数据相减可以连接后(相所要求的条件,比如是同一个人的工资和扣的养老金之类,连接条件就是同一个人的标识,可能是身份证号,职工号什么的)相减,这没有什么啊,两表连接后进行数据操作就可以了!句中一般和一个表中数据的加减没有区别:
select A.gongzi-B.yanglao as Result,* form A,B where A.gonghao = B.gonghao