Take the 2-minute tour ×
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. It's 100% free, no registration required.

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:

ID    | ATM     | DATE_SUBMITTED        | PROBLEM_NAME     | STATUS
---------------------------------------------------------------------
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(tickets.id) > 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 at 13:41
add comment

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.