This topic is locked

Limit the number of records returned in a Report

6/5/2008 6:01:35 AM
PHPRunner General questions
L
ld_ski author

Hi,
I have a sales database with hundreds of products, and I would like to run a report that shows me the TOP 20 selling products.
I have created the report, have the total sales ordered in descending order so the top selling items are at the top, but cannot get it to recognize the command to Limit the number or records it shows in the report.
Here's the code:
SELECT

SUM(testimport.QUANTITY) AS `Total Qty`,

testimport.REP_PERIOD AS `Date`,

product.product_description AS Product,

branch.branch_name AS Shop,

SUM((quantityprice)-vat_amt) AS `Total Sales`

FROM testimport

INNER JOIN product ON testimport.PRODUCT = product.product_tillref

INNER JOIN branch ON testimport.BRANCH = branch.branch_id

WHERE testimport.`TYPE` ='PAID'

GROUP BY testimport.REP_PERIOD, product.product_description, branch.branch_name, testimport.PRICE

ORDER BY (quantity
price)-vat_amt DESC

LIMIT 10
The last line is what I thought from reading about MySQL should go in, but it gives this error: ....check the manual that corresponds to your MySQL version for the right syntax to use near 'limi 0,200' line 13...
Using MySql 5.0.X
Many thanks,

Loredana

J
Jane 6/5/2008

Hi,
unfortunately PHPRunner doesn't support LIMIT on the "Edit SQL query" tab.

As workaround create view in teh database directly with this query and then use this view in the PHPRunner.

Here is a sample:

create view `viewname` as

SELECT

SUM(testimport.QUANTITY) AS `Total Qty`,

...

ORDER BY (quantity*price)-vat_amt DESC

LIMIT 10

L
ld_ski author 6/5/2008

Thanks. I'll try it and report back.

L
ld_ski author 6/5/2008

Worked great, thanks!