How do I select only one data from a list of records with repeated data?

0

I am looking for a way to show only the first data of each record that my table has.

I have a table called detalle_cuota where:

  • insert the amount of each quota
  • the amounts according to the amount of fees that you say you will have the course
  • every 3 records an increase of 20% of the previous amount.

The problem is that when I am going to process the first payment, I need to automatically see the first amount of the fees belonging to that course.

These are the tables:

What I want to do is to appear on the form when processing the first payment, the amount 1 and if it is paid to change something paid. And so on, the amounts that the student has to pay will come out to me.

Something like this should be my form.

Ex: Course: FOOD, FIRST PAY: 44,000,

Ex: Course: PASTRY, FIRST PAYMENT: 66,000

Ex: Course: FOOD, SECOND PAYMENT: 44,000

    
asked by 26.08.2017 в 05:30
source

2 answers

0

Ready the query you need is the following:

SELECT TOP(1) C.curso, B.id_cuota, B.monto  --  Seleccionamos el primer registro(Necesitas el Order para que funcione)
FROM DETALLE_CUOTA AS B
INNER JOIN CUOTAS AS A
    ON (A.ID = B.ID)
INNER JOIN CURSOS_ABIERTOS AS C
    ON (A.id_curso = C.id)
WHERE A.id_curso = "CursoQueBuscas" --  Tu curso a buscar
    AND B.estado = false    --  Solo los que no estan pagados.
ORDER BY C.curso, B.id_cuota ASC    --  Ordenamos el resultado

Remember to specify the "Course that You look for" and [B.State] to use it in the condition as what it represents for you, true - paid, false - no. Greetings!

    
answered by 26.08.2017 / 17:26
source
0

Good morning

Depending on how you have fully thought about your structure; in relation to the only thing that you suggest, you add one more field, for example pagado which will be a flag by which you identify which one was already made, so that you have it false if it has not yet been received and true in case it does .

With the change that I suggest it will be that according to id_cuota (I assume it identifies if it is food, pastry, etc ...) it would be for example to obtain the following one to cover:

SELECT ID, ID_CUOTA, MONTO FROM [TU TABLA QUE MUESTRAS]
WHERE ID (SELECT MIN(ID) 
          FROM [TU TABLA QUE MUESTRAS] WHERE PAGADO=0 
          and ID_CUOTA=[IDENTIFICADOR DE AQUIEN CORRESPONDE LA CUOTA])
      and ID_CUOTA=[IDENTIFICADOR DE AQUIEN CORRESPONDE LA CUOTA]

I hope it serves you.

EDITED

SELECT cuotaPagar.ID, cuotaPagar.ID_CUOTA, cuotaPagar.MONTO 
FROM [TU TABLA QUE MUESTRAS] as cuotaPagar
WHERE cuotaPagar.ID (SELECT MIN(cuotaxPagar.ID) 
          FROM [TU TABLA QUE MUESTRAS] cuotaxPagar
          WHERE cuotaxPagar.PAGADO=0 
          and cuotaxPagar.ID_CUOTA=cuotaPagar.ID_CUOTA)
      and cuotaPagar.ID_CUOTA=[IDENTIFICADOR DE AQUIEN CORRESPONDE LA CUOTA]

or try with just

SELECT cuotaPagar.ID, MIN(cuotaPagar.ID_CUOTA) as ID_CUOTA, cuotaPagar.MONTO 
FROM [TU TABLA QUE MUESTRAS] as cuotaPagar
WHERE cuotaPagar.PAGADO=0
      and cuotaPagar.ID_CUOTA=[IDENTIFICADOR DE AQUIEN CORRESPONDE LA CUOTA]
    
answered by 26.08.2017 в 06:12