数据库:SQL SERVER 2000
工具:DELPHI7
题目:客户管理,详情:
其中包括了订单管理,在客户列表中当点击一个客户时,在右侧的列表中要求列出这个客户的所有订单,订单列表信息包括订单ID,产品名称,数量,单价,金额,销售日期等,订单在数据库中由订单表和订单详表组成.而订单详表中的产品ID又与产品表相关联.也就是说,如果想让订单列表显示了那些信息就要与四个表有关联.即客户表(客户ID)订单表(客户ID,订单ID)订单详表(订单ID,产品ID)产品表(产品ID),我要怎么写SQL语句才能实现订单列表中所显示的那些信息,重要的是还要与客户信息相一致,就是能够随着客户列表的点击改变订单列表的内容.我的做法:
select orders.orderid,products.productname,orderdetails.Quantity,orderdetails.unitprice,orderdetails.quantity * orderdetails.unitprice as meony,orders.orderdate
from orders,orderdetails,products
where (orders.orderid=orderdetails.orderid) and (orderdetails.productid=products.productid)
但是什么也查不到,而且不能与客户列表的点击动作保持响应.
请高手指点一下.
工具:DELPHI7
题目:客户管理,详情:
其中包括了订单管理,在客户列表中当点击一个客户时,在右侧的列表中要求列出这个客户的所有订单,订单列表信息包括订单ID,产品名称,数量,单价,金额,销售日期等,订单在数据库中由订单表和订单详表组成.而订单详表中的产品ID又与产品表相关联.也就是说,如果想让订单列表显示了那些信息就要与四个表有关联.即客户表(客户ID)订单表(客户ID,订单ID)订单详表(订单ID,产品ID)产品表(产品ID),我要怎么写SQL语句才能实现订单列表中所显示的那些信息,重要的是还要与客户信息相一致,就是能够随着客户列表的点击改变订单列表的内容.我的做法:
select orders.orderid,products.productname,orderdetails.Quantity,orderdetails.unitprice,orderdetails.quantity * orderdetails.unitprice as meony,orders.orderdate
from orders,orderdetails,products
where (orders.orderid=orderdetails.orderid) and (orderdetails.productid=products.productid)
但是什么也查不到,而且不能与客户列表的点击动作保持响应.
请高手指点一下.
from customer a left join
order b on a.cust_id = b.cust_id left join
orderdetails c on b.orderid = c.orderid left join
products d on c.productid = d.productid
from customer a left join
order b on a.cust_id = b.cust_id left join
orderdetails c on b.orderid = c.orderid left join
products d on c.productid = d.productid 后面加上条件
where a.cust_id = '' 就能满足你的要求了
create procedure p_test
@CustomID int
as
begin
select ...
from customer a left join
order b on a.cust_id = b.cust_id left join
orderdetails c on b.orderid = c.orderid left join
products d on c.productid = d.productid and a.id=@CustomID
end