M
M
Maxim2015-09-21 19:26:20
PHP
Maxim, 2015-09-21 19:26:20

How to calculate the correct statistics from the database?

Hello!
Essence such, there is a table finance
In it records of a type
id | dates | manager | office | finance
1 | Date | Vasya | Gagarin | 15000
2 | Date | Petya | Gorky | 14000
3 | Date | Vanya | Gagarin | 9000
how to formulate a query so that the records are summarized and displayed like this:
Gorky 14000
Gagarin 24000
I do this, but finances are not displayed:

$result = mysql_query("SELECT   DISTINCT office
 FROM finance  where dates 
BETWEEN '".$_GET['dateo']."' AND '".$_GET['datep']."' group by office");

Answer the question

In order to leave comments, you need to log in

2 answer(s)
H
heartdevil, 2015-09-21
@maksse

Hello.
Here is a query like this

SELECT office, SUM(finance)
FROM finance
WHERE dates BETWEEN  '".$_GET['dateo']."' AND '".$_GET['datep']."'
GROUP BY office

D
Dmitry Evgrafovich, 2015-09-22
@Tantacula

you should read about sql injections.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question