Connecting Tech Pros Worldwide Forums | Help | Site Map

SQL for frequency-related results

PI
Guest
 
Posts: n/a
#1: Nov 17 '08
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
Guest
 
Posts: n/a
#2: Nov 17 '08

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

PI
Guest
 
Posts: n/a
#3: Nov 17 '08

re: SQL for frequency-related results


problem solved - solution available at
http://groups.google.co.uk/group/com...e143e44?hl=en#
Jerry Stuckle
Guest
 
Posts: n/a
#4: Nov 17 '08

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
==================
PI
Guest
 
Posts: n/a
#5: Nov 17 '08

re: SQL for frequency-related results


Thanks Jerry,
apologies for multiposting - but how do I crosspost instead?
Jerry Stuckle
Guest
 
Posts: n/a
#6: Nov 17 '08

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