开发者

SQL server 2008: How to get the start date and end date of my data?

As a newb, I already know that I will be berated for asking this question, but I did not find the answer on the site here and could use some help...

I have a table that lists data by the day, and by type. For example

Transaction  |  Date  | Type
-----------------------------
Updat    | 11/7/2008  | Cash-out
Update   | 11/10/2008 | Wrote-check 
Deposit  | 11/11/2009 | Cashed Check 
Update   | 11/18/2008 | Wrote check 
Deposit  | 11/19/2009 | 开发者_运维百科Cashed Check 

What I'm trying to do, is find the very first occurrence of each transaction type, and the very last occurrence of each transaction type. so I'm trying to figure out an sql statement that I can write that will return something like this:

Transaction  |  First Date  | Last Date  |
----------------------------------------------
Update       | 11/7/2008    | 11/18/2008 |
Deposit      | 11/11/2009   | 1/19/2009  |

any ideas?


SELECT Transaction, Min([date])  AS [First Date] , Max([Date]) AS [Last Date]
FROM myTable GROUP BY Transaction


SELECT
     transaction,
     MIN([date]) AS [First Date],
     MAX([date]) AS [Last Date]
FROM
     My_Table
GROUP BY
     transaction
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜