MYSQL multi-table query, query statement
This is the case, there are three tables,
A table with all the sales staff performance, probably fields as follows:
Name yeji date record with the name of the sales staff (36), performance (sales and balance payment amount, generally referred to as the credit), time (date of payment)
Zhang SAN | | 5000.00 2020.10.15
Li si | | 6000.00 2020.10.15
Zhang SAN | | 8000.00 2020.10.16
Fifty and | | 2500.00 2020.10.17
,,,,,,,
Select SUM (yeji) from a where clause date> * and date<* group by normal display the name of each of the name and the total turnover
B table, with all the customer name, sales staff and overtime records: the overtime is the record, no overtime, no record,
The name, the date the salesman name, date of overtime,
Zhang SAN | 2020.10.9
Li si | 2020.10.9
Zhang SAN | 2020.10.10
Select count (id) from b where date> * and date<* group by the name can be displayed normal name and number of overtime,
.
C table all sales staff visit customer information:
Kehu, cj, date, name, respectively is: customer name, whether or not clinch a deal (1, 0), date, the sales person name,
Sun Jiachun | 1 | 2020.10.05 | zhang
Liu yuxi | 1 | 2020.10.07 | zhang
Banqiao | | 0 2020.10.09 | li si
Select count (kehu), count (if cj=1, 0) as cj form c where date> * and date<* group by the name the normal display total number of sales personnel visiting, total volume,
Now need to look at any time (the date time range), sales staff performance, displayed on the table:
Sales staff name, collection, number of days work overtime, the customer
Name, yeji, jiaban kehus
Excuse me, how to write the query it, for a long time, or data, such as overtime amplified many times, or amplified many payment amount,