简体   繁体   English

如何获得某个值的最大日期和阶段名称?

[英]How do I get the max date and stage name for a certain value?

I am working on a query to pull the max date that is greater than a given period of time and have it return the value that is in that date. 我正在执行一个查询,以拉出大于给定时间段的最大日期,并使其返回该日期中的值。 I'm working from a salesforce table and want to pull the max date that an opportunity is in and return the stage name that it is in. The date has to be greater than 5-1-14. 我正在从salesforce表中工作,并希望提取机会所在的最大日期并返回其所在的阶段名称。该日期必须大于5-1-14。 So do I have to break this up into multiple queries? 那么我是否必须将其分解为多个查询? Give me the max date then return the stage name that its in. Any help would be appreciated!! 给我最大日期,然后返回其所在的阶段名称。任何帮助将不胜感激! Thanks! 谢谢!

SELECT OpportunityID,     

  Max(case when CREATEDDATE < '2014-05-01' THEN STAGENAME END) as Q1_FY15_Stage 

FROM [BVSFWarehouse].[dbo].[sf_OPPORTUNITYHISTORY]

GROUP by OPPORTUNITYID

You can filter your SELECT statement with a WHERE clause to limit the dates. 您可以使用WHERE子句过滤SELECT语句以限制日期。 Try: 尝试:

SELECT
     OpportunityID
    ,STAGENAME
    ,MAX(CREATEDATE)
FROM BVSWarehouse.dbo.sf_OPPORTUNITYHISTORY
WHERE
    CREATEDATE > '2015-05-01'
GROUP BY
     OpportunityID
    ,STAGENAME

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM