By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE cliente_rbdigital
(
cli_id INT PRIMARY KEY,
cli_data_cadastro DATE NOT NULL
);
CREATE TABLE contrato_rbdigital
(
cont_id INT PRIMARY KEY,
cont_cliente_id INT NOT NULL,
cont_data_vencimento DATE NOT NULL
);
CREATE TABLE titulo_rbdigital
(
titulo_id INT PRIMARY KEY,
contratoid INT NOT NULL,
dataven DATE NOT NULL,
datapag DATE,
valorpago MONEY
);
INSERT INTO cliente_rbdigital (cli_id, cli_data_cadastro)
VALUES (10472, '2020-07-31'),
(10471, '2020-07-31'),
(10470, '2020-07-31'),
(10469, '2020-07-31'),
(10468, '2020-07-31'),
(10467, '2020-07-31'),
(10466, '2020-07-31'),
(10465, '2020-07-31'),
(10464, '2020-07-31'),
(10463, '2020-07-31');
INSERT INTO contrato_rbdigital (cont_id, cont_cliente_id, cont_data_vencimento)
VALUES (39486, 10472, '2020-08-30'),
cli_id | cli_data_cadastro | cont_id | cont_data_vencimento | titulo_id | dataven | datapag | valorpago | situacao |
---|---|---|---|---|---|---|---|---|
10463 | 2020-07-31 | 39459 | 2020-08-29 | 39382 | 2020-07-31 | 2020-07-30 | 9.9000 | Pago |
10464 | 2020-07-31 | 39458 | 2021-07-30 | 39381 | 2020-08-02 | 2020-07-30 | 238.8000 | Pago |
10466 | 2020-07-31 | 39467 | 2020-08-29 | 39391 | 2020-08-02 | 2020-07-30 | 19.9000 | Pago |
10468 | 2020-07-31 | 39473 | 2020-08-29 | 39396 | 2020-08-02 | 2020-07-30 | 19.9000 | Pago |
10469 | 2020-07-31 | 39488 | 2021-01-27 | 39411 | 2020-08-01 | 2020-07-31 | 119.4000 | Pago |
10471 | 2020-07-31 | 39484 | 2021-01-27 | 39407 | 2020-08-03 | 2020-07-31 | 119.4000 | Pago |
10472 | 2020-07-31 | 39486 | 2020-08-30 | 39409 | 2020-08-03 | null | 0.0000 | Não Pago |
10470 | 2020-07-31 | 39483 | 2020-10-29 | 39406 | 2020-08-03 | null | 0.0000 | Não Pago |
10467 | 2020-07-31 | 39472 | 2021-01-26 | 39395 | 2020-08-02 | null | 0.0000 | Não Pago |
10465 | 2020-07-31 | 39463 | 2020-08-29 | 39386 | 2020-08-02 | null | 0.0000 | Não Pago |