Connecting Tech Pros Worldwide Help | Site Map

SQL for frequency-related results

  #1  
Old November 17th, 2008, 09:25 AM
PI
Guest
 
Posts: n/a
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.
  #2  
Old November 17th, 2008, 09:45 AM
PI
Guest
 
Posts: n/a

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.uk | 0000-00-00 00:00:00 | Unknown |
| 2 | 47569BZ | 03LH459 | 1 |
joe@bloggs.co.uk | 0000-00-00 00:00:00 | Unknown |
| 3 | 83284AD | 03LH260 | 1 |
joe@bloggs.co.uk | 0000-00-00 00:00:00 | Unknown |
| 4 | 83284AD | 03LH459 | 1 |
joe@bloggs.co.uk | 0000-00-00 00:00:00 | Unknown |
| 5 | 85669FJ | 03LH260 | 3 |
joe@bloggs.co.uk | 2008-11-14 09:54:08 | Unknown |
| 6 | 85669FJ | 03LH459 | 7 |
joe@bloggs.co.uk | 2008-11-14 09:54:08 | Unknown |
| 7 | 02429ZH | 03LH260 | 3 |
joe@bloggs.co.uk | 2008-11-14 10:28:55 | Unknown |
| 8 | 02429ZH | 03LH459 | 7 |
joe@bloggs.co.uk | 2008-11-14 10:28:55 | Unknown |
+-----------+-------------+---------------+----------
+----------------------------+---------------------+--------------+
Thanks

  #3  
Old November 17th, 2008, 11:45 AM
PI
Guest
 
Posts: n/a

re: SQL for frequency-related results


problem solved - solution available at
http://groups.google.co.uk/group/com...e143e44?hl=en#
  #4  
Old November 17th, 2008, 12:15 PM
Jerry Stuckle
Guest
 
Posts: n/a

re: SQL for frequency-related results


PI wrote:
Quote:
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@attglobal.net
==================
  #5  
Old November 17th, 2008, 03:55 PM
PI
Guest
 
Posts: n/a

re: SQL for frequency-related results


Thanks Jerry,
apologies for multiposting - but how do I crosspost instead?
  #6  
Old November 17th, 2008, 05:45 PM
Jerry Stuckle
Guest
 
Posts: n/a

re: SQL for frequency-related results


PI wrote:
Quote:
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@attglobal.net
==================
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Displaying SQL Results Zack2008 answers 9 August 9th, 2008 12:45 AM
Connection pooling questions crbd98@yahoo.com answers 16 December 13th, 2006 05:15 PM
random record with SELECT TOP does NOT work Jimmy answers 48 September 18th, 2006 02:45 PM
SQL Stored procedure into a datagrid Amy answers 3 November 17th, 2005 11:22 AM
Help with an import to SQL TeleTech answers 2 July 20th, 2005 04:57 AM