Sql Server2005 查询sql语句怎么写

2024-12-15 22:20:53
推荐回答(4个)
回答1:

Easy!

SELECT Order.orderNumber,
User.userName,
Pruduct.productName,
Shop.shopName
FROM Order, User, Cart, Pruduct, Shop
WHERE Order.userId = User.serId
AND Cart.orderId = Order.orderId
AND Cart.productId = Pruduct.productId
AND Shop.shopId = Order.shopId

这样效率会高一点
SELECT Order.orderNumber,
User.userName,
Pruduct.productName,
Shop.shopName
FROM Order INNER JOIN USER ON Order.userId = User.serId
INNER JOIN Cart, Pruduct ON Cart.orderId = Order.orderId AND Cart.productId = Pruduct.productId
INNER JOIN Shop ON Shop.shopId = Order.shopId

回答2:

先抢下沙发。马上解决

select order.orderid,user.username,pruduct.productname,(select shop.shopname from shop where shopid = order.orderid) from (order right join user

on order.userid = user.userid ) right join shop on order.shopid = shop.shopid;

给分吧

回答3:

select orderNumber as 订单编号,
(select userName from User) as 会员名称,
(select productName from Pruduct) as 商品名称,
(select shopName from Shop) as 供应商名称 from Order

回答4:

SELECT Order.orderNumber,
User.userName,
Pruduct.productName,
Shop.shopName
FROM User right join Order on Order.userId = User.serId right join Cart on Order.orderId=Cart.orderId right join Pruduct on Cart.productId=Product.productId right join Shop on Order.shopId=Shop.shopId