I have a payment table where in a field called ESTADO_COMPRA
shows the following values ( EN CRÉDITO, PENDIENTE DE PAGO
), then I want to count in fictitious fields those that still have credit and those that have already expired without paying. Something like that.
---------------------------------------------------------------------
|Cod_ruc. | nom_empresas. | Contactados. | EnCredito. | Pendiente |
|-------------------------------------------------------------------|
| 2045621 | LEXCORP ENT. | 20 | 1 | 2 |
| 2045577 | Wayne Enterpri. | 35 | 3 | 1 |
---------------------------------------------------------------------
The original table is more or less like this
-----------------------------------------------------------------------------
| cod_comp | codi_ruc | nombr_empresa | comprado | tipo_pago | Estado_Venta |
|---------------------------------------------------------------------------|
| C0000001 | 2045621 | LEXCORP ENT. | 350 | 15 días | EN CREDITO |
| C0000002 | 2045621 | LEXCORP ENT. | 150 | 20 días | VENCIDO |
| C0000003 | 2045621 | LEXCORP ENT. | 1150 | 15 días | VENCIDO |
| C0000004 | 2045577 | WAYNE ENTPR. | 3520 | 30 días | EN CREDITO |
| C0000005 | 2045577 | WAYNE ENTPR. | 4010 | 30 días | PAGADO |
| C0000006 | 2045577 | WAYNE ENTPR. | 5050 | 30 días | EN CREDITO |
| C0000007 | 2045577 | WAYNE ENTPR. | 2050 | 30 días | VENCIDO |
| C0000008 | 2045577 | WAYNE ENTPR. | 2150 | 30 días | EN CREDITO |
-----------------------------------------------------------------------------
I complicate in dividing the count of Estado_Venta
into 2 fields, En crédito
and Pendiente
. * I forgot to mention that the contacted field comes from a JOIN from the CustomerCalls table (contacted, cod_ruc, detail_called), here simply with a Count (cod_ruc) I can count the number of contacts a specific client has had.