Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Query...

4 réponses
Avatar
PePiCK
J'ai une question en toute apparence toute b=EAte...

Voici un exemple de donn=E9es:

FRED 2008 2 10.00
FRED 2008 3 11.00
FRED 2008 4 12.00
FRED 2008 6 13.00
FRED 2008 8 14.00
FRED 2008 10 15.00
FRED 2008 12 16.00
MARC 2008 2 12.00
MARC 2008 4 14.00
MARC 2008 5 16.00

Je veux une requ=EAte qui va me formater le tout de cette fa=E7on:

FRED 2008 2 10.00
FRED 2008 3 11.00
FRED 2008 4 12.00
FRED 2008 5 0.00
FRED 2008 6 13.00
FRED 2008 7 0.00
FRED 2008 8 14.00
FRED 2008 9 0.00
FRED 2008 10 15.00
FRED 2008 11 0.00
FRED 2008 12 16.00
FRED 2009 1 0.00
MARC 2008 2 12.00
MARC 2008 3 0.00
MARC 2008 4 14.00
MARC 2008 5 16.00
MARC 2008 6 0.00
MARC 2008 7 0.00
MARC 2008 8 0.00
MARC 2008 9 0.00
MARC 2008 10 0.00
MARC 2008 11 0.00
MARC 2008 12 0.00
MARC 2009 1 0.00

C'est con, je n'y arrive pas... :(

4 réponses

Avatar
EmanuelL
Bonjour PePiCK,

Une requete du genre :
SELECT Nom, Annee, Mois, Total FROM MaTable ORDER BY Nom, Annee, Mois,
Total

;-)

PePiCK a formulé la demande :
J'ai une question en toute apparence toute bête...

Voici un exemple de données:

FRED 2008 2 10.00
FRED 2008 3 11.00
FRED 2008 4 12.00
FRED 2008 6 13.00
FRED 2008 8 14.00
FRED 2008 10 15.00
FRED 2008 12 16.00
MARC 2008 2 12.00
MARC 2008 4 14.00
MARC 2008 5 16.00

Je veux une requête qui va me formater le tout de cette façon:

FRED 2008 2 10.00
FRED 2008 3 11.00
FRED 2008 4 12.00
FRED 2008 5 0.00
FRED 2008 6 13.00
FRED 2008 7 0.00
FRED 2008 8 14.00
FRED 2008 9 0.00
FRED 2008 10 15.00
FRED 2008 11 0.00
FRED 2008 12 16.00
FRED 2009 1 0.00
MARC 2008 2 12.00
MARC 2008 3 0.00
MARC 2008 4 14.00
MARC 2008 5 16.00
MARC 2008 6 0.00
MARC 2008 7 0.00
MARC 2008 8 0.00
MARC 2008 9 0.00
MARC 2008 10 0.00
MARC 2008 11 0.00
MARC 2008 12 0.00
MARC 2009 1 0.00

C'est con, je n'y arrive pas... :(



--

*!* -----------------------------------
EmanuelL
Membre d'AtoutFox
www.atoutfox.org
Avatar
Fred BROUARD
Une solution :

CREATE TABLE T_NUM (N INT)

INSERT INTO T_NUM VALUES (1)
INSERT INTO T_NUM VALUES (2)
INSERT INTO T_NUM VALUES (3)
...
INSERT INTO T_NUM VALUES (9999)

CREATE TABLE T (nom VARCHAR(8), annee INT, num INT, montant DECIMAL(16,2))

INSERT INTO T VALUES ('FRED', 2008, 2, 10.00)
INSERT INTO T VALUES ('FRED', 2008, 3, 11.00)
INSERT INTO T VALUES ('FRED', 2008, 4, 12.00)
INSERT INTO T VALUES ('FRED', 2008, 6, 13.00)
INSERT INTO T VALUES ('FRED', 2008, 8, 14.00)
INSERT INTO T VALUES ('FRED', 2008, 10, 15.00)
INSERT INTO T VALUES ('FRED', 2008, 12, 16.00)
INSERT INTO T VALUES ('MARC', 2008, 2, 12.00)
INSERT INTO T VALUES ('MARC', 2008, 4, 14.00)
INSERT INTO T VALUES ('MARC', 2008, 5, 16.00)

SELECT DISTINCT TT.nom, TT.annee, TT.N, COALESCE(T.montant, TT.montant)
AS montant
FROM T
RIGHT OUTER JOIN (SELECT DISTINCT nom, annee, N, 0 AS montant
FROM T AS T1
CROSS JOIN T_NUM
WHERE N BETWEEN 1 AND (SELECT MAX(num)
FROM T AS T2
WHERE T1.nom =
T2.nom)) AS TT
ON T.nom = TT.nom
AND T.annee = TT.annee
AND T.num = TT.N
ORDER BY 1, 2, 3

Il y a sans doute plus simple en utilisant les fonctions de fenêtrage
comme ROW_NUMBER() OVER(.... sous 2005.

A +


PePiCK a écrit :
J'ai une question en toute apparence toute bête...

Voici un exemple de données:

FRED 2008 2 10.00
FRED 2008 3 11.00
FRED 2008 4 12.00
FRED 2008 6 13.00
FRED 2008 8 14.00
FRED 2008 10 15.00
FRED 2008 12 16.00
MARC 2008 2 12.00
MARC 2008 4 14.00
MARC 2008 5 16.00

Je veux une requête qui va me formater le tout de cette façon:

FRED 2008 2 10.00
FRED 2008 3 11.00
FRED 2008 4 12.00
FRED 2008 5 0.00
FRED 2008 6 13.00
FRED 2008 7 0.00
FRED 2008 8 14.00
FRED 2008 9 0.00
FRED 2008 10 15.00
FRED 2008 11 0.00
FRED 2008 12 16.00
FRED 2009 1 0.00
MARC 2008 2 12.00
MARC 2008 3 0.00
MARC 2008 4 14.00
MARC 2008 5 16.00
MARC 2008 6 0.00
MARC 2008 7 0.00
MARC 2008 8 0.00
MARC 2008 9 0.00
MARC 2008 10 0.00
MARC 2008 11 0.00
MARC 2008 12 0.00
MARC 2009 1 0.00

C'est con, je n'y arrive pas... :(




--
Frédéric BROUARD, MVP SQL Server, expert bases de données et langage SQL
Le site sur le langage SQL et les SGBDR : http://sqlpro.developpez.com
Audit, conseil, expertise, formation, modélisation, tuning, optimisation
*********************** http://www.sqlspot.com *************************
Avatar
EmanuelL
Mea culpa, j'avais pas fais attention aux 0.
Bravo Fred!


Fred BROUARD avait soumis l'idée :
Une solution :

CREATE TABLE T_NUM (N INT)

INSERT INTO T_NUM VALUES (1)
INSERT INTO T_NUM VALUES (2)
INSERT INTO T_NUM VALUES (3)
...
INSERT INTO T_NUM VALUES (9999)

CREATE TABLE T (nom VARCHAR(8), annee INT, num INT, montant DECIMAL(16,2))

INSERT INTO T VALUES ('FRED', 2008, 2, 10.00)
INSERT INTO T VALUES ('FRED', 2008, 3, 11.00)
INSERT INTO T VALUES ('FRED', 2008, 4, 12.00)
INSERT INTO T VALUES ('FRED', 2008, 6, 13.00)
INSERT INTO T VALUES ('FRED', 2008, 8, 14.00)
INSERT INTO T VALUES ('FRED', 2008, 10, 15.00)
INSERT INTO T VALUES ('FRED', 2008, 12, 16.00)
INSERT INTO T VALUES ('MARC', 2008, 2, 12.00)
INSERT INTO T VALUES ('MARC', 2008, 4, 14.00)
INSERT INTO T VALUES ('MARC', 2008, 5, 16.00)

SELECT DISTINCT TT.nom, TT.annee, TT.N, COALESCE(T.montant, TT.montant) AS
montant
FROM T
RIGHT OUTER JOIN (SELECT DISTINCT nom, annee, N, 0 AS montant
FROM T AS T1
CROSS JOIN T_NUM
WHERE N BETWEEN 1 AND (SELECT MAX(num)
FROM T AS T2
WHERE T1.nom = T2.nom)) AS
TT
ON T.nom = TT.nom
AND T.annee = TT.annee
AND T.num = TT.N
ORDER BY 1, 2, 3

Il y a sans doute plus simple en utilisant les fonctions de fenêtrage comme
ROW_NUMBER() OVER(.... sous 2005.

A +


PePiCK a écrit :
J'ai une question en toute apparence toute bête...

Voici un exemple de données:

FRED 2008 2 10.00
FRED 2008 3 11.00
FRED 2008 4 12.00
FRED 2008 6 13.00
FRED 2008 8 14.00
FRED 2008 10 15.00
FRED 2008 12 16.00
MARC 2008 2 12.00
MARC 2008 4 14.00
MARC 2008 5 16.00

Je veux une requête qui va me formater le tout de cette façon:

FRED 2008 2 10.00
FRED 2008 3 11.00
FRED 2008 4 12.00
FRED 2008 5 0.00
FRED 2008 6 13.00
FRED 2008 7 0.00
FRED 2008 8 14.00
FRED 2008 9 0.00
FRED 2008 10 15.00
FRED 2008 11 0.00
FRED 2008 12 16.00
FRED 2009 1 0.00
MARC 2008 2 12.00
MARC 2008 3 0.00
MARC 2008 4 14.00
MARC 2008 5 16.00
MARC 2008 6 0.00
MARC 2008 7 0.00
MARC 2008 8 0.00
MARC 2008 9 0.00
MARC 2008 10 0.00
MARC 2008 11 0.00
MARC 2008 12 0.00
MARC 2009 1 0.00

C'est con, je n'y arrive pas... :(





--

*!* -----------------------------------
EmanuelL
Membre d'AtoutFox
www.atoutfox.org
Avatar
helios services
Fred BROUARD a écrit :
Une solution :

CREATE TABLE T_NUM (N INT)

INSERT INTO T_NUM VALUES (1)
INSERT INTO T_NUM VALUES (2)
INSERT INTO T_NUM VALUES (3)
...
INSERT INTO T_NUM VALUES (9999)

CREATE TABLE T (nom VARCHAR(8), annee INT, num INT, montant DECIMAL(16,2))

INSERT INTO T VALUES ('FRED', 2008, 2, 10.00)
INSERT INTO T VALUES ('FRED', 2008, 3, 11.00)
INSERT INTO T VALUES ('FRED', 2008, 4, 12.00)
INSERT INTO T VALUES ('FRED', 2008, 6, 13.00)
INSERT INTO T VALUES ('FRED', 2008, 8, 14.00)
INSERT INTO T VALUES ('FRED', 2008, 10, 15.00)
INSERT INTO T VALUES ('FRED', 2008, 12, 16.00)
INSERT INTO T VALUES ('MARC', 2008, 2, 12.00)
INSERT INTO T VALUES ('MARC', 2008, 4, 14.00)
INSERT INTO T VALUES ('MARC', 2008, 5, 16.00)

SELECT DISTINCT TT.nom, TT.annee, TT.N, COALESCE(T.montant, TT.montant)
AS montant
FROM T
RIGHT OUTER JOIN (SELECT DISTINCT nom, annee, N, 0 AS montant
FROM T AS T1
CROSS JOIN T_NUM
WHERE N BETWEEN 1 AND (SELECT MAX(num)
FROM T AS T2
WHERE T1.nom =
T2.nom)) AS TT
ON T.nom = TT.nom
AND T.annee = TT.annee
AND T.num = TT.N
ORDER BY 1, 2, 3

Il y a sans doute plus simple en utilisant les fonctions de fenêtrage
comme ROW_NUMBER() OVER(.... sous 2005.

A +


PePiCK a écrit :
J'ai une question en toute apparence toute bête...

Voici un exemple de données:

FRED 2008 2 10.00
FRED 2008 3 11.00
FRED 2008 4 12.00
FRED 2008 6 13.00
FRED 2008 8 14.00
FRED 2008 10 15.00
FRED 2008 12 16.00
MARC 2008 2 12.00
MARC 2008 4 14.00
MARC 2008 5 16.00

Je veux une requête qui va me formater le tout de cette façon:

FRED 2008 2 10.00
FRED 2008 3 11.00
FRED 2008 4 12.00
FRED 2008 5 0.00
FRED 2008 6 13.00
FRED 2008 7 0.00
FRED 2008 8 14.00
FRED 2008 9 0.00
FRED 2008 10 15.00
FRED 2008 11 0.00
FRED 2008 12 16.00
FRED 2009 1 0.00
MARC 2008 2 12.00
MARC 2008 3 0.00
MARC 2008 4 14.00
MARC 2008 5 16.00
MARC 2008 6 0.00
MARC 2008 7 0.00
MARC 2008 8 0.00
MARC 2008 9 0.00
MARC 2008 10 0.00
MARC 2008 11 0.00
MARC 2008 12 0.00
MARC 2009 1 0.00

C'est con, je n'y arrive pas... :(






mais peut on faire confiance à quelqu'un qui prétends coder plus de
65536 valeurs sur 2 octets ?

http://groups.google.com/group/fr.comp.applications.sgbd/msg/621527f995585842?dmode=source





et donc les écrits ont été bannis de wikipedia

--
Dr Thierry HOLZ
HELIOS SERVICES
180 rue de la croix du chene
60250 HEILLES
www.openqm.com02.net
www.pick.com02.net