指出的SQL查询 - 拉出所有者包含%WF%的最小日期

时间:2012-01-12 15:11:57

标签: sql

我正在进行查询,我试图在表格中提取所有者包含WF的最短日期。

表格如下:

Order Number
Create Date
Modified Date
Owner

对于每个订单,我需要拉出所有者包含%WF%的最小修改日期。

非常感谢任何帮助。

感谢。

以下是我的查询:

select distinct (ol.order_no),
min(os.assgn_dt) as MinDate,
ow.owner_desc, 
ol.created_Date,
md.media_type_desc,
ow.owner_desc,
st.status_type_Desc,
os.comment,
tt.team_type_desc,
br.sdescrip as Branch,
ol.bgrp_cnt


from order_log ol
join activity_type att on ol.activity_type_id = att.activity_type_id
join branches br on ol.branch = br.lbranch
join regions rg on br.lregion = rg.lregion
join businessunit bu on rg.lbusinessunit = bu.lbusinessunit
join vwCurrentStatus vcs on vcs.order_no = ol.order_no
join order_status os on os.order_no = vcs.order_no
join owner ow on os.owner_name = ow.owner_id
join status_type st on st.status_type_id = os.status_type_id
join team_type tt on ow.team_type_id = tt.team_type_id
join media_type md on ol.media_type_id = md.media_type_id
join rep_name_xref rnx on rnx.order_no = ol.order_no
join rep_names rn on rn.user_id = rnx.user_id

where ow.owner_desc like '%WF%' 
and ol.created_date > '01-01-2012'
and att.activity_type_id in ('14','16')
and tt.team_type_desc in ('1-10 Membership Team','government')

group by ol.order_no, ow.owner_desc, ol.created_Date,md.media_type_desc,ow.owner_desc,st.status_type_Desc,     os.comment, tt.team_type_desc,br.sdescrip, ol.bgrp_cnt

3 个答案:

答案 0 :(得分:0)

类似的东西:

select order_number,min(modified_date) from orders where owner like '%WF%' group by order_number;

答案 1 :(得分:0)

关于您在评论中所说的内容,请尝试以下方法:

SELECT t.Owner, t.ModifiedDate
FROM tablename t
WHERE t.ModifiedDate = (SELECT MIN(t2.ModifiedDate)
                      FROM tablename t2
                      WHERE t2.Owner like '%WF%')

它将为您提供Owners ModifiedDate equal to Min(ModifiedDate) Owner '%WF%'与{{1}}的列表{/ 1}}。

答案 2 :(得分:0)

如果您想要所有者包含“WF”的所有订单的最低订购日期,请尝试:

SELECT MIN(ModifiedDate)
FROM MyTable
WHERE Owner like '%WF%'