SQL题目不会做求教

2025-01-07 16:44:20
推荐回答(2个)
回答1:

假设Customer表主键是ID, Order表主键是ID
1)select sum(O.Revenue) from Customer C, Order O where C.ID=O.CustomerID and C.Name='张三';
3)select C.ID,sum(O.Revenue) from Customer C, Order O where C.ID=O.CustomerID
4)从第4题来看这个题目出的有问题。Order表应该是每个Order一行,一个
customer有多行。怎么能将Revenue减少10%?任意一行去减吗?

回答2:

建表
create table customer
(
ID int primary key,Name char(10)
)
go
create table [order]
(
ID int primary key,CustomerID int foreign key
references customer(id) , Revenue float
)
go
--查询
select Customer.ID, sum( isnull([Order].Revenue,0) )
from customer full join [order]
on( [order].customerid=customer.id )
group by customer.id