27,579
社区成员
发帖
与我相关
我的任务
分享
create table t_A
(
id int,
series decimal(4,2),
actualamount decimal(4,2)
)
insert into t_A values(1,1.0,2)
insert into t_A values(1,1.5,5)
insert into t_A values(2,1.3,3)
insert into t_A values(2,2,4)
------------------------------
create table t_B
(
id int,
qty decimal(4,2)
)
insert into t_B values(1,1)
insert into t_B values(2,2.5)
select B.id,state=case when A.series*B.qty>=A.actualamount then '正确' else '失败' end
from t_A A,t_B B where A.id=B.id
select a.*,判断字段=case when a.SERIES*b.QTY<=a.ACTUALAMOUNT then 1 else 0 end
from a inner join b on a.id=b.id
--是不是这样
create table A(ID int, SERIES decimal(6,1), ACTUALAMOUNT int)
insert a
select 1 ,1.0 ,2 union all
select 1 ,1.5 ,5 union all
select 2 ,1.3 ,3 union all
select 2 ,2 ,4
create table B(ID int, QTY decimal(6,1))
insert b
select 1 ,1 union all
select 2 ,2.5
if exists (select 1 from a inner join b on a.id=b.id and a.SERIES*b.QTY<=a.ACTUALAMOUNT)
print('正确')
else
print('错误')
/*
正确
*/
create table A(ID int, SERIES decimal(6,1), ACTUALAMOUNT int)
insert a
select 1 ,1.0 ,2 union all
select 1 ,1.5 ,5 union all
select 2 ,1.3 ,3 union all
select 2 ,2 ,4
create table B(ID int, QTY decimal(6,1))
insert b
select 1 ,1 union all
select 2 ,2.5
select a.*,显示=case when a.SERIES*b.QTY<=a.ACTUALAMOUNT then '正确' else '错误' end
from a inner join b on a.id=b.id
/*
ID SERIES ACTUALAMOUNT 显示
----------- --------------------------------------- ------------ ----
1 1.0 2 正确
1 1.5 5 正确
2 1.3 3 错误
2 2.0 4 错误
(4 行受影响)
*/
select a.*,case when a.SERIES*b.QTY<=a.ACTUALAMOUNT then '正确' else '错误' end
from a inner join b on a.id=b.id