I have a table with roughly 150,000 entries in the form of the followingstocknumber price dateacq datesold id_num01407535 9969 2008-08-28 2008-08-28 2805501407538 7235 2008-08-28 2008-09-14 8950301407542 7325 2008-08-28 2008-09-17 4195501407554 6886 2008-08-28 2008-09-17 8484601407556 3992 2008-08-28 2008-09-06 9253401407557 7163 2008-08-28 2008-09-17 1002401407558 4180 2008-08-28 2008-09-17 2829301407563 4195 2008-08-28 2008-09-17 8257101423568 3256 2008-08-29 2008-09-21 3567501254698 9856 2008-08-29 2008-09-21 5787701446454 8456 2008-08-28 2008-09-17 8465501465654 5231 2008-08-29 2008-09-21 4345601498465 8565 2008-08-29 2008-09-21 6785701421984 1236 2008-08-29 2008-09-21 4567501465498 6545 2008-08-28 2008-09-14 56767I want to write a query that won't display entries that have a specific combination of dateacq and datesold more than 5 times.for example the combination with dateacq of '2008-08-28' and datesold of '2008-09-17' appears 6 times, so i want to remove it from the result set. The combination of dateacq of '2008-08-29' and datesold of '2008-09-12' appears 5 times, so remove that as well.The result set should be stocknumber price dateacq datesold id_num01407535 9969 2008-08-28 2008-08-28 2805501407538 7235 2008-08-28 2008-09-14 8950301407556 3992 2008-08-28 2008-09-06 9253401465498 6545 2008-08-28 2008-09-14 56767I started the query by doing thisselect stocknumber, price,dateadd(dd, datediff(dd, 0, first_occurrence), 0) dateacq, dateadd(dd,datediff(dd, 0, last_occurence), 0) datesold,max(id_num) as id_numfrom bluenile_inventorygroup by stocknumber, price, dateadd(dd, datediff(dd, 0,first_occurrence), 0), dateadd(dd, datediff(dd, 0, last_occurence),0)
Not sure where to take it now, any help would be great