我相信它们是我问题的简单答案。
我有 2 个表 - 一个订单标题表(每个订单一行,称为“Order”)和一个订单详细信息表(每个订单标题 1 行或多行,称为“Order_Line”)。我正在使用 Sql Server2005 和他们的 SSRS 报告工具。我只想取回一行,但我得到了每个订单的详细信息表中有多少行。我需要加入明细表以获取我想与其他订单标题级别项目一起显示的值。
我尝试选择不同但得到相同的结果。我的查询是:
select o.order_num, o.cust_num, c.cust_desc, o.shipto_num, o.st_name, o.st_address1, o.ent_date,
o.ord_date, o.req_date, ol.order_line, ol.seq_num, u.user_desc, ol.orig_inv_num, ol.prod_num,
p.prod_desc1, ol.prod_desc1, ol.prod_desc2, ol.grs_price, ol.disc_pct, ol.net_price, ol.ord_qty,
ol.opn_qty, ol.pck_qty, ol.bo_qty, ol.shp_qty, rs.rsn_code_desc, ol.supp_cde, ol.line_ctr,
v.vend_desc, ca.pline_desc, ca.major_grp, ol.major_grp, w.whse_desc, o.wb,s.ship_via_desc,
sa.slsm_desc, t.ar_term_desc,
o.shp_date, o.sys_num, o.inv_Flag, o.inv_num, o.tot_ord_$,o.inv_date, o.ord_src, r.route_desc,
o.cred_type, o.cred_num, o.total_sale
from [order] o
left outer join order_line ol on o.order_num = ol.order_num
left outer join customer c on o.cust_num = c.cust_no
left outer join ship_via s on o.ship_via_num = s.ship_via_id
left outer join whse_addr w on o.shp_whse = w.whse_num
left outer join salesman sa on o.slsm_num = sa.slsm_num
left outer join terms t on o.ar_term_num = t.ar_term_num
left outer join [route] r on o.route_num = r.route_num
left outer join product p on ol.prod_num = p.prod_num
left outer join prc_ov_rsn rs on ol.prc_ov_rsn_code = rs.rsn_cod
left outer join vend v on ol.prim_vend_num = v.vend_num
left outer join [user_id] u on ol.[user_id] = u.[user_num]
left outer join category ca on ol.pline_Num = ca.pline_Id
where o.cust_num = '606797'
order by o.cust_num, o.shipto_num, o.order_num
无论每个订单有多少 Order_Line 记录,我怎样才能让查询只返回一行?