PC SOFT

FOROS PROFESIONALES
WINDEVWEBDEV y WINDEV Mobile

Inicio → Reports & Queries → Requete SQL multi colonne
Requete SQL multi colonne
Iniciado por Jean-François P, 11,abr. 2019 09:56 - 4 respuestas
Miembro registrado
97 mensajes
Popularité : +1 (1 vote)
Publicado el 11,abril 2019 - 09:56
Bonjour,

Je suis assez novice en sql et je voulais savoir si il est possible de sommer deux colonnes en fonctions de deux autres colonnes.
Je m'explique :

J'ai ma BDD avec mes 5 colonnes
- Date
- Mode de paiement 1
- Mode de paiement 2
- Montant paiement 1
- Montant paiement 2

Est il possible de faire une somme des paiements en fonction du mode de paiement et de la date?

Bien cordialement

Jef
Miembro registrado
97 mensajes
Popularité : +1 (1 vote)
Publicado el 11,abril 2019 - 10:12
Exemple :

Date | Mode de paiement 1 | Mode de paiement 2 | Montant paiement 1 | Montant paiement 2
01/02/2019 | Espèce | Chèque | 2€ | 2€
01/02/2019 | Chèque | CB | 4€ | 4€
02/02/2019 | CB | Espèce | 6€ | 6€
02/02/2019 | Espèce | CB | 2€ | 2€
03/02/2019 | CB | Chèque | 4€ | 4€
03/02/2019 | Chèque | Espèce | 6€ | 6€


Le résultat serait :

01/02/2019 | Espèce | 2€
01/02/2019 | Chèque | 6€
01/02/2019 | CB | 4€
02/02/2019 | Espèce | 8€
02/02/2019 | Chèque | 0€
02/02/2019 | CB | 8€
03/02/2019 | Espèce | 6€
03/02/2019 | Chèque | 10€
03/02/2019 | CB | 4€

Je sèche vraiment, merci de votre aide.

Bien cordialement

Jef
Miembro registrado
2 mensajes
Publicado el 17,abril 2019 - 16:57
il suffit de faire un SUM et un GROUP BY
Miembro registrado
5 mensajes
Publicado el 29,julio 2022 - 13:54
I think You have to try this:

UPDATE table1
SET a = t2.a, b = t2.b, .......
FROM table2 t2
WHERE table1.id = t2.id
That should work in most SQL dialects, excluding Oracle.

And yes - it's a lot of typing - it's the way SQL does this.
Miembro registrado
5 mensajes
Publicado el 30,julio 2022 - 07:24
Britneymcdaniel escribió:
I think You have to try this: https://www.kohlsfeedback.onl/

UPDATE table1
SET a = t2.a, b = t2.b, .......
FROM table2 t2
WHERE table1.id = t2.id
That should work in most SQL dialects, excluding Oracle.

And yes - it's a lot of typing - it's the way SQL does this.

In the real world, you will often want to select multiple columns. Luckily, SQL makes this really easy. To select multiple columns from a table, simply separate the column names with commas!