SQL for frequency-related results

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • PI

    SQL for frequency-related results

    Hi guys,
    I need some assistance please: Since PHP guys usually have SQL skills,
    I decided to post this question here. How do I structure a SQL command
    to return frequency-related results from a database. For example, if I
    wanted the query to return the top 5 entries in a table within
    specified dates. By top 5 (N), I mean the records (values) in a given
    table that have occurred the most within that table. Perhaps, to help
    you help me, if user requests for a product were entered into a table,
    and I wanted to find out the most requested product in the month of
    May or within the last 6 months, how will the SQL query be please?
    Thanks.
  • PI

    #2
    Re: SQL for frequency-related results

    Hi Guys,
    The following information is added to make my question clearer

    The table schema is:
    +---------------+--------------+------+-----+---------+----------------
    +
    | Field | Type | Null | Key | Default | Extra
    |
    +---------------+--------------+------+-----+---------+----------------
    +
    | requestID | int(15) | NO | PRI | NULL | auto_increment
    |
    | requestNum | varchar(255) | YES | | NULL |
    |
    | itemRequested | varchar(255) | YES | | NULL |
    |
    | quantity | int(15) | YES | | NULL |
    |
    | userEmail | varchar(255) | YES | | NULL |
    |
    | date | datetime | YES | | NULL |
    |
    | location | varchar(255) | YES | | NULL |
    |
    +---------------+--------------+------+-----+---------+----------------
    +

    And the table viewed may look like this:

    +-----------+-------------+---------------+----------
    +----------------------------+---------------------+--------------+
    | requestID | requestNum | itemRequested | quantity |
    userEmail | date | location |
    +-----------+-------------+---------------+----------
    +----------------------------+---------------------+--------------+
    | 1 | 47569BZ | 03LH260 | 1 |
    joe@bloggs.co.u k | 0000-00-00 00:00:00 | Unknown |
    | 2 | 47569BZ | 03LH459 | 1 |
    joe@bloggs.co.u k | 0000-00-00 00:00:00 | Unknown |
    | 3 | 83284AD | 03LH260 | 1 |
    joe@bloggs.co.u k | 0000-00-00 00:00:00 | Unknown |
    | 4 | 83284AD | 03LH459 | 1 |
    joe@bloggs.co.u k | 0000-00-00 00:00:00 | Unknown |
    | 5 | 85669FJ | 03LH260 | 3 |
    joe@bloggs.co.u k | 2008-11-14 09:54:08 | Unknown |
    | 6 | 85669FJ | 03LH459 | 7 |
    joe@bloggs.co.u k | 2008-11-14 09:54:08 | Unknown |
    | 7 | 02429ZH | 03LH260 | 3 |
    joe@bloggs.co.u k | 2008-11-14 10:28:55 | Unknown |
    | 8 | 02429ZH | 03LH459 | 7 |
    joe@bloggs.co.u k | 2008-11-14 10:28:55 | Unknown |
    +-----------+-------------+---------------+----------
    +----------------------------+---------------------+--------------+
    Thanks

    Comment

    • PI

      #3
      Re: SQL for frequency-related results

      problem solved - solution available at

      Comment

      • Jerry Stuckle

        #4
        Re: SQL for frequency-related results

        PI wrote:
        problem solved - solution available at
        http://groups.google.co.uk/group/com...e143e44?hl=en#
        Which was the correct place to post this in the first place - this was
        NOT a PHP question and should not have been posted in this newsgroup.

        Additionally, when you do post in multiple newsgroups, please crosspost
        - not multipost.

        --
        =============== ===
        Remove the "x" from my email address
        Jerry Stuckle
        JDS Computer Training Corp.
        jstucklex@attgl obal.net
        =============== ===

        Comment

        • PI

          #5
          Re: SQL for frequency-related results

          Thanks Jerry,
          apologies for multiposting - but how do I crosspost instead?

          Comment

          • Jerry Stuckle

            #6
            Re: SQL for frequency-related results

            PI wrote:
            Thanks Jerry,
            apologies for multiposting - but how do I crosspost instead?
            If you look at the form when you post your message, one of the things it
            says, right under the "To Newsgroups:" is:

            (Separate multiple groups with commas)

            --
            =============== ===
            Remove the "x" from my email address
            Jerry Stuckle
            JDS Computer Training Corp.
            jstucklex@attgl obal.net
            =============== ===

            Comment

            Working...