bonjour,
J'ai un soucis avec une requête :
j'ai une table qui contient les donnée comme suit :
client /// trimestre /// achat /// vente /// année
2545 /// 1 /// 160 /// 120 /// 2018
2545 /// 2 /// 150 /// 120/// 2018
2545 /// 3 /// 130 /// 0 /// 2018
2545 /// 4 /// 180 /// 12 /// 2018
2545 /// 1 /// 110 /// 220 /// 2019
2545 /// 2 /// 0 /// 0 /// 2019
je veux faire une requête qui me retourne les client actif ,
si achat OU vente >= 150 dans le trimestre 1, 2 ,3,ou4 alors c'est un client actif sinon non actif
il suffit quil est un seul trimestre ou il satisfait les condition pour être considéré comme actif
le resultat final doit etre comme suit
client /// annee /// flag_actif
2545 /// 2018 /// 1
2545 /// 2019 /// 1
voici mon codeOr ma requette affiche comme suit
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 select num_client,annee, case when ((achat>150 or depense>=150) and TRIMESTRE=1 and annee >=2018 ) or ((mnt_achats_cb_trim>150 or mnt_retraits_cb_trim>=150) and TRIMESTRE=2 ) or ( (mnt_achats_cb_trim>150 or mnt_retraits_cb_trim>=150) and TRIMESTRE=3) or ( (mnt_achats_cb_trim>150 or mnt_retraits_cb_trim>=150) and TRIMESTRE=4 ) then 1 else 0 end as flag actif from donnee ct where num_client=2545 and annee >=2018
num_client /// annee /// flag_actif
2545 /// 2018 /// 1
2545 /// 2018 /// 1
2545 /// 2018 /// 0
2545 /// 2018 /// 1
2545 /// 2019 /// 1
2545 /// 2019 /// 0
on dirait qu'il affiche le flag_actif par semestre alors que mois je veux qu'il l'affiche sur toute l'année.
Pouvez vous m'aidez svp
Partager