I need a line-by-line extract without grouping all clientID's, see below.
I'm writing a quick extract to find how many times our customers have booked a product so we can see what their second, 3rd or 4th booking is.
select c.clientid, c.bookref, left(c.tourno, 6) as tourref, c.book_date
from cust c
where c.book_date between '2018-01-01' and ' 2020-01-01'
order by clientid asc, book_date asc
This is pretty basic SQL and it turns a result with one line per booking. What I need to do is count the number of times that ClientID appears, and by ordering the table by "clientid asc, book_date asc", I should be able to come up with a long list of bookings and what booking number corresponds to each line.
Unfortunately, all the help examples I've seen basically group the ID column in, so I can see that ID "255253" has a count of 7 (and thus 7 bookings), but no idea what those bookings are.
Thank you! I'm using Advantage SQL by the way.
I think the best way to explain it is, imagine you have an ascending list of clientID's in date order in column A on excel, then you apply this formula to cell B2:
=IF(A2=A1,B1+1,1)