Picking data from database that appeard just once in a month
I have a table and in that bank transactions are recorded. 开发者_StackOverflow社区I want to pull out the users who made transaction just once in a month. That means their transaction count == 1 for that month.
I am recording card_number, timestamp etc..
SELECT *
FROM transactions
GROUP BY card_number, month
HAVING COUNT(card_number) = 1
Check This
select Card_Number,
DATEPART(m, [TimeStamp] )MonthNo,
COUNT(1) TxnCount
from Transactions
group by Card_Number,
DATEPART(m, [TimeStamp] )
having COUNT(1)=1
I am assuming that your table structure is somthing like below.
Card_Number int,
TimeStamp datetime
精彩评论