COUNT number of times prior to specified time, self-join?
问题 For simplicity let's assume I have two tables: billing with the following fields bill_id (primary, unique key, int), person_id , bill_date , and billing_detail containing bill_id and service_type . First of all I would like a list of clients ( person_id ) who were billed for a given range of services in a given period, so simply SELECT billing.person_id, billing.bill_date FROM billing INNER JOIN billing_detail ON billing.bill_id = billing_detail.bill_id WHERE billing_detail.service_type IN