我有个订单表跟顾客表,用sql语句如果找出每月购买一次的顾客,关键是每月一次这个条件怎么写。
Select 客户,convert(varchar(6),时间字段,112) From 订单跟踪表 Group By convert(varchar(6),时间字段,112) Having Count(*)=1
参照http://www.cnblogs.com/mapeng-11/archive/2011/03/09/1978417.html这个博客。。。
Select 客户 From 订单跟踪表 Group By 客户 Having Count(*)=1
Select 客户,年月 From 订单跟踪表 Group By 客户,年月 Having Count(*)=1
SELECT 客户,DATEPART(MONTH,'日期') AS 月份
FROM 订单跟踪表
GROUP BY 客户,DATEPART(MONTH,'日期')
HAVING COUNT(*) = 1