Query Question


#1

How do I word a query for the following:

I want to know how many orders a particular customer has ordered of a certain product for any 30 day period (or month) last year, so I can see if their orders are lower or higher than this year.

I have a database called “mydatabase”

The main table is called “ordering”

the fields I have are:

customerid (name of company)
ordernumber (automatically incremented)
orderdate (date they ordered it)
orderedby (salesman)
duedate (due to them)
ProdA
ProdB
ProdC

I have Mysql version 4.0.18 and it comes with a program called “MysqlTool” version .95

I’m new to Mysql, and only know some simple “select” queries.

Thanks for any help.


#2

Believe or not that is all you are doing (“simple select”). Only you will be put qualifications on it. check out the mysql manual using WHERE statements ( http://dev.mysql.com/doc/mysql/en/SELECT.html ).

Now if you have no idea what the heck I am talking about or can’t understand the manual check out here - http://www.geekgirls.com/menu_databases.htm to learn more about databases and how to use them (very good stuff here if you know nothing about databases) and here - http://www.sqlcourse.com/ - to learn about basic SQL (check out page 3 for info on WHERE clauses). If you feel up to the challenge you can also check out here - http://sqlcourse2.com/ to learn more advanced SQL.

I know this doesn’t answer your question specifically (I used to hate that) but if you will be working with PHP even recreationally you will be using databases. The more you know about them the better. “Give a man a fish…” Cliche but true.

If you need any more assistance let us know and we will try to point you in the right direction.


#3

Thanks! I agree I need to learn, maybe you can help me understand an error message?

I wrote a Query and the error message was as follows:

“You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near ‘; LIMIT 0, 100’ at line 1”
Now this MysqlTool I have has two fields in the limit clause you can fill in:

LIMIT Clause: Start at row #__ Display rows per page ____

I had it set at Row “1” and “100” rows per page. I don’t have any idea why it failed, and I couldn’t find anything in the manual on how to adjust limit clause to match this type of query.

Here is the query I wrote:

SELECT customerID, orderdate, prodA FROM custdatabase ORDER BY orderdate, customerID;


#4

UPDATE:

Well what do you know, I got it to work!!

The problem was the semicolon ; at the end. in the MYSQL manual, it had a semi colon at the end of all of the examples, so I included one. Apparently this thing I use doesn’t like them.

Now I have something to play with. Thanks for the link.


#5

Congratulations! Have fun.