Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Lets say I have 2 tables: atms & tickets each atm has many tickets.

ATM table:

ID    | NAME
A0109 | ATM 1
A0227 | ATM 2
etc.  | etc.

Ticket table:

1     | A0109   | 2014-02-01 17:00:00   | OUT_OF_PAPER     | CLOSED
2     | A0109   | 2014-02-08 17:00:00   | BLANK_SCREEN     | OPEN
etc.  | etc.    | etc.                  | etc.             | etc.

In general repeating rule (more than 1 ticket per ATM), I can use HAVING condition where COUNT( > 1 and GROUP them by ATM ID. But the problem is, the "repeating" criteria is different. The condition considered as repeating is any ATM that has more than 2 tickets in 1 week or more than 3 tickets in 1 month. How can I create SQL query for this problem?

Any help would be appreciated, thanks in advance

share|improve this question
@Mihai what you propose is just not valid syntax. – ypercubeᵀᴹ Feb 12 '14 at 13:41

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.