Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
tswiss
Starting Member
7 Posts |
Posted - 2014-09-03 : 14:41:23
|
I want to select customers that were present for at least 2 of 3 days (Monday, Tuesday, Wednesday).I don't care what combination, just that the customers where present at least twice. Below is 3 of 3. How do I modify for any 2 of 3?WHERE database.date = Monday and database.date = Tuesday and database.date = Wednesday |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2014-09-03 : 15:44:40
|
What is the data type of database.date?Tara KizerSQL Server MVP since 2007http://weblogs.sqlteam.com/tarad/ |
|
|
tswiss
Starting Member
7 Posts |
Posted - 2014-09-03 : 16:27:27
|
Actual dates like '2014-02-25' |
|
|
tswiss
Starting Member
7 Posts |
Posted - 2014-09-03 : 21:48:57
|
Actual dates like '2014-02-25' |
|
|
tswiss
Starting Member
7 Posts |
Posted - 2014-09-03 : 22:20:53
|
datetime |
|
|
Bustaz Kool
Master Smack Fu Yak Hacker
1834 Posts |
Posted - 2014-09-04 : 12:45:41
|
This is difficult since we have no idea what your table looks like...[SoapBox]Stop using reserved words for column names![/SoapBox][CODE]declare @CustomerAttendance table ( CustId int, date date )insert into @CustomerAttendancevalues (1, '20140901'), -- 1 = All 3 (1, '20140902'), (1, '20140903'), (2, '20140901'), -- 2 = 2/3 (2, '20140902'), (3, '20140901'), -- 3 = 1/3 (3, '20140901'), -- Multiple entry of same date (4, '20140904'), -- 4 = Outside the range (4, '20140905'), (4, '20140906')--/**/select * from @CustomerAttendance;with UQ_Attendanceas (select distinct *from @CustomerAttendancewhere [date] between '20140901' and '20140903')select CustIDfrom UQ_Attendancegroup by CustIDhaving count(*) >= 2[/CODE] Too often we enjoy the comfort of opinion without the discomfort of thought. - John F. Kennedy |
|
|
|
|
|
|
|