Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2003
    Location
    London, UK
    Posts
    1

    Question Unanswered: tricky bit (at least for me)

    Hi

    I am studying SQL and Oracle in the Uni and I've got stuck on some questions. Maybe anyone can help me here?
    The problem 1 is: how do I write an SQL query in order to find the most frequent customers? Here is the data from my table:
    ORDE STAFF_NO DATE_OF_O CUST_NO
    ---- ---------- --------- ----------
    1 1 12-NOV-03 3
    2 2 05-NOV-03 1
    3 3 15-OCT-03 2
    4 2 12-NOV-03 4
    5 3 12-NOV-03 2
    6 1 12-NOV-03 5
    7 8 12-NOV-03 2
    8 4 12-NOV-03 7

    Do I have to use COUNT(*)? It doesn't seem to work. Please, help!!!
    Thanks in advance.

  2. #2
    Join Date
    Apr 2003
    Location
    Minneapolis, MN
    Posts
    273
    Hi,
    What is your threshold value you call it as frequent customers?
    Say, for e.g, if a customer buys n times then, your threshold value is n.

    So , now run the following SQL query which gives you the name of customers who has placed orders >= n times. ( obviously, you can not say customer a frequent customer if he/she buys 1 or 2 times).

    SELECT custo_no
    FROM whatever
    GROUP BY custo_no
    HAVING count (*) > = n;

    Here n is any number. (say, if you want theh list of custo_no who has placed an order more than 10 times thant n = 10)

    Thanks

    Hings
    ========

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •