我有一张桌子,并且记录了银行交易。我想拉出一个月内只进行一次交易的用户。这意味着他们的交易次数= = 1当月。
我正在记录card_number,时间戳等。
答案 0 :(得分:3)
SELECT *
FROM transactions
GROUP BY card_number, month
HAVING COUNT(card_number) = 1
答案 1 :(得分:0)
检查此
select Card_Number,
DATEPART(m, [TimeStamp] )MonthNo,
COUNT(1) TxnCount
from Transactions
group by Card_Number,
DATEPART(m, [TimeStamp] )
having COUNT(1)=1
我假设您的表格结构如下所示。
Card_Number int,
TimeStamp datetime