创建特定的mysql查询

juzqafwq  于 2021-06-23  发布在  Mysql
关注(0)|答案(0)|浏览(213)

我必须为每个客户创建一个函数,在这个函数中,我可以找到他租金最高的年份和月份。现在我已经完成了:

Select CUSTOMER_ID, NAME, SURNAME, count(distinct RENT_ID_PK) as total 
from t_rent
inner join t_customer on t_customer.CUSTOMER_ID_PK=t_rent.CUSTOMER_ID 
group by CUSTOMER_ID 
order by total desc;

老实说,我不知道该如何前进。有什么建议吗?
@编辑

CREATE TABLE `database`.`t_rent` (
  `RENT_ID_PK` INT(10) NOT NULL AUTO_INCREMENT,
  `CAR_ID` INT(10) NOT NULL,
  `CUSTOMER_ID` INT(10) NOT NULL,
  `STARTING_DATE` DATE NOT NULL,
  `FINISH_DATE` DATE NOT NULL,
  `COMPANY_ID_START` INT NOT NULL,
  `COMPANY_ID_FINISH` INT NOT NULL,
  `RENT_COST` INT UNSIGNED NOT NULL,
  PRIMARY KEY (`RENT_ID_PK`));

CREATE TABLE `database`.`t_customer` (
  `CUSTOMER_ID_PK` INT(10) NOT NULL AUTO_INCREMENT,
  `NAME` VARCHAR(45) NOT NULL,
  `SURNAME` VARCHAR(45) NOT NULL,
  `E_MAIL` VARCHAR(45) NOT NULL,
  `PHONE_NO` VARCHAR(45) NOT NULL,
  `PERSONAL_NO` VARCHAR(45) NOT NULL,
  `CREDIT_CARD_NO` VARCHAR(45) NOT NULL,
  `ADRESS` INT(10) NOT NULL,
  PRIMARY KEY (`CUSTOMER_ID_PK`));

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题