* 基本信息,由于合同号太多,所以这边就以一个有重复数据的合同id为例
+-------------+----------------------------+------------+----------+
+-------------+----------------------------+------------+----------+
| 27310 | A00-SHEN-05-2018-06-004613 | 2941.18 | 20180628 |
| 27310 | A00-SHEN-05-2018-06-004613 | 5882.36 | 20180629 |
| 27310 | A00-SHEN-05-2018-06-004613 | 8823.54 | 20180630 |
| 27310 | A00-SHEN-05-2018-06-004613 | 11764.72 | 20180701 |
| 27310 | A00-SHEN-05-2018-06-004613 | 14705.90 | 20180702 |
| 27310 | A00-SHEN-05-2018-06-004613 | 17647.08 | 20180703 |
| 27310 | A00-SHEN-05-2018-06-004613 | 20588.26 | 20180704 |
| 27310 | A00-SHEN-05-2018-06-004613 | 23529.44 | 20180705 |
| 27310 | A00-SHEN-05-2018-06-004613 | 26470.62 | 20180706 |
| 27310 | A00-SHEN-05-2018-06-004613 | 29411.80 | 20180707 |
| 27310 | A00-SHEN-05-2018-06-004613 | 32352.98 | 20180708 |
+-------------+----------------------------+------------+----------+
12 rows in set (0.00 sec)
* 查询每个最新合同的信息,由于合同号太多,所以这边就以一个有重复数据的合同id为例
select contract_no, contract_id, city_name, receivable,date from
(select * from crm_report_accounting_income_2015_online where contract_id = 27310 ORDER BY `date` desc) p GROUP BY contract_id
+----------------------------+-------------+-----------+------------+----------+
+----------------------------+-------------+-----------+------------+----------+
+----------------------------+-------------+-----------+------------+----------+
1 row in set (0.00 sec)