IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Requêtes et SQL. Discussion :

Probleme requete fonction agregat


Sujet :

Requêtes et SQL.

  1. #1
    Membre à l'essai
    Profil pro
    Inscrit en
    Juillet 2009
    Messages
    24
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2009
    Messages : 24
    Points : 11
    Points
    11
    Par défaut Probleme requete fonction agregat
    Bonjour,

    J'ai essayé de faire plusieurs formules avec la fonction vraifaux mais au final dans ma derniere colonne de formule, on me dis que cela fait parti de fonction d'agregat : ci joint ma requete tres longue en SQL

    Code sql : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    SELECT Restaurant.[Centre de cout], Restaurant.[Nom du restaurant], Loyers.Loyer, Loyers.[Indice de base], Indice.[trimestre/Mois], Indice.Indice, Indice.[Indice N-1], Indice.[Indice N-2], Loyers.[ANNEE REVISION], Loyers.[type revision], Indice.Année, Indice.[Année N-1], Indice.[Année N-2], Indice.[Année N-3], IIf([annee revision]="N-1",[année N-1],indice.Année) AS [Année revise], IIf([ANNEE REVISION]="N-1",IIf([type revision]="triennal",[année N-3],[année N-1]),IIf([type revision]="triennal",[année N-2],[indice].[Année])) AS [Année révisés], IIf([ANNEE REVISION]="N-1",IIf([type revision]="triennal",IIf(Int(([indice].[année]-[loyers].[année])/3)*3+[loyers].[année]=[indice].[année],[indice].[année],IIf(Int(([indice].[année]-[loyers].[année])/3)*3+[loyers].[année]=[indice].[année N-1],[indice].[année N-1],[indice].[année N-2])),[année N-1]),IIf([type revision]="triennal",IIf(Int(([indice].[année]-[loyers].[année])/3)*3+[loyers].[année]=[indice].[année N-1],[indice].[année N-1],IIf(Int(([indice].[année]-[loyers].[année])/3)*3+[loyers].[année]=[indice].[année N-2],[indice].[année N-2],[indice].[année N-3])),[indice].[Année])) AS [Année à reviser], IIf([ANNEE REVISION]="N-1",IIf([type revision]="triennal",IIf(Int(([indice].[année]-[loyers].[année])/3)*3+[loyers].[année]=[indice].[année],[indice].[indice],IIf(Int(([indice].[année]-[loyers].[année])/3)*3+[loyers].[année]=[indice].[indice N-1],[indice].[indice N-1],[indice].[indice N-2])),[indice N-1]),IIf([type revision]="triennal",IIf(Int(([indice].[année]-[loyers].[année])/3)*3+[loyers].[année]=[indice].[année N-1],[indice].[indice N-1],IIf(Int(([indice].[année]-[loyers].[année])/3)*3+[loyers].[année]=[indice].[année N-2],[indice].[indice N-2],[indice].[indice N-3])),[indice].[indice]))*[loyer]/[indice de base] AS [Nouveau loyer], IIf([ANNEE REVISION]="N-1",IIf([type revision]="triennal",IIf(Int(([indice].[année]-[loyers].[année])/3-3)*3+[loyers].[année]=[indice].[année],[indice].[indice N-1],IIf(Int(([indice].[année]-[loyers].[année])/3-3)*3+[loyers].[année]=[indice].[indice N-1],[indice].[indice N-2],[indice].[indice N-3])),[indice N-2]),IIf([type revision]="triennal",IIf(Int(([indice].[année]-[loyers].[année])/3-3)*3+[loyers].[année]=[indice].[année N-1],[indice].[indice N-2],IIf(Int(([indice].[année]-[loyers].[année])/3-3)*3+[loyers].[année]=[indice].[année N-2],[indice].[indice N-3],[indice].[indice N-4])),[indice].[indice N-1]))*[loyer]/[indice de base] AS [Loyer N-1], [loyer N-1]-[loyer] AS a, IIf([a]<1,[loyer],[loyer N-1]) AS [Ancien loyer], IIf([loyers].[nom mois]=1,(31-[loyers].[jour]+1)*([nouveau loyer]/4)/90+([ancien loyer]/4)*([jour]-1)/90,[nouveau loyer]) AS janvier
    FROM Bailleur INNER JOIN (Restaurant INNER JOIN (Loyers INNER JOIN Indice ON (Loyers.[Trimestre/Mois] = Indice.[trimestre/Mois]) AND (Loyers.[type indice] = Indice.[Type Indice])) ON Restaurant.[Centre de cout] = Loyers.[Centre de cout]) ON Bailleur.[Numero bailleur] = Loyers.[Numero bailleur]
    GROUP BY Restaurant.[Centre de cout], Restaurant.[Nom du restaurant], Loyers.Loyer, Loyers.[Indice de base], Indice.[trimestre/Mois], Indice.Indice, Indice.[Indice N-1], Indice.[Indice N-2], Loyers.[ANNEE REVISION], Loyers.[type revision], Indice.Année, Indice.[Année N-1], Indice.[Année N-2], Indice.[Année N-3], IIf([annee revision]="N-1",[année N-1],indice.Année), IIf([ANNEE REVISION]="N-1",IIf([type revision]="triennal",[année N-3],[année N-1]),IIf([type revision]="triennal",[année N-2],[indice].[Année])), IIf([ANNEE REVISION]="N-1",IIf([type revision]="triennal",IIf(Int(([indice].[année]-[loyers].[année])/3)*3+[loyers].[année]=[indice].[année],[indice].[année],IIf(Int(([indice].[année]-[loyers].[année])/3)*3+[loyers].[année]=[indice].[année N-1],[indice].[année N-1],[indice].[année N-2])),[année N-1]),IIf([type revision]="triennal",IIf(Int(([indice].[année]-[loyers].[année])/3)*3+[loyers].[année]=[indice].[année N-1],[indice].[année N-1],IIf(Int(([indice].[année]-[loyers].[année])/3)*3+[loyers].[année]=[indice].[année N-2],[indice].[année N-2],[indice].[année N-3])),[indice].[Année])), IIf([ANNEE REVISION]="N-1",IIf([type revision]="triennal",IIf(Int(([indice].[année]-[loyers].[année])/3)*3+[loyers].[année]=[indice].[année],[indice].[indice],IIf(Int(([indice].[année]-[loyers].[année])/3)*3+[loyers].[année]=[indice].[indice N-1],[indice].[indice N-1],[indice].[indice N-2])),[indice N-1]),IIf([type revision]="triennal",IIf(Int(([indice].[année]-[loyers].[année])/3)*3+[loyers].[année]=[indice].[année N-1],[indice].[indice N-1],IIf(Int(([indice].[année]-[loyers].[année])/3)*3+[loyers].[année]=[indice].[année N-2],[indice].[indice N-2],[indice].[indice N-3])),[indice].[indice]))*[loyer]/[indice de base], IIf([ANNEE REVISION]="N-1",IIf([type revision]="triennal",IIf(Int(([indice].[année]-[loyers].[année])/3-3)*3+[loyers].[année]=[indice].[année],[indice].[indice N-1],IIf(Int(([indice].[année]-[loyers].[année])/3-3)*3+[loyers].[année]=[indice].[indice N-1],[indice].[indice N-2],[indice].[indice N-3])),[indice N-2]),IIf([type revision]="triennal",IIf(Int(([indice].[année]-[loyers].[année])/3-3)*3+[loyers].[année]=[indice].[année N-1],[indice].[indice N-2],IIf(Int(([indice].[année]-[loyers].[année])/3-3)*3+[loyers].[année]=[indice].[année N-2],[indice].[indice N-3],[indice].[indice N-4])),[indice].[indice N-1]))*[loyer]/[indice de base], [loyer N-1]-[loyer], IIf([a]<1,[loyer],[loyer N-1]), IIf([loyers].[nom mois]=1,(31-[loyers].[jour]+1)*([nouveau loyer]/4)/90+([ancien loyer]/4)*([jour]-1)/90,[nouveau loyer])
    HAVING (((Indice.Année)=2006));

    Pouvez vous m'aider s'il vous plais?

    Momo

  2. #2
    Membre émérite Avatar de curt
    Homme Profil pro
    Ingénieur Etudes
    Inscrit en
    Mars 2006
    Messages
    1 575
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur Etudes
    Secteur : Bâtiment Travaux Publics

    Informations forums :
    Inscription : Mars 2006
    Messages : 1 575
    Points : 2 550
    Points
    2 550
    Par défaut
    Bonsoir momo93240,

    mets ta base en pièce jointe en expliquant :

    • Ce que tu veux obtenir

    • Ce qui ne fontionne pas


    Bonne soirée.
    Curt

  3. #3
    Membre à l'essai
    Profil pro
    Inscrit en
    Juillet 2009
    Messages
    24
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2009
    Messages : 24
    Points : 11
    Points
    11
    Par défaut
    Ci-joint ma base de donnée et désolé Phillipe pour la presentation.

    En faite, je voudrais faire 12 requêtes qui correspondent aux mois de l’année :

    Janvier : si le « mois revise » de la table « loyers »=1 alors « nouveau loyer »/4*(31-« jour » de la table loyer+1)/90+ « ancien loyer »* (« jour » de la table loyers-1)/90 sinon « nouveau loyer »/4*31/90 sauf si « mois revise »> janvier dans ce cas « ancien loyer »/4*31/90

    La meme chose pour les autres mois en remplacant 31 par le nombre de jour par mois
    Et 90 correspond au premier trimestre (31+28+31)
    Donc a partir de avril j’aimerai utilisé à la place de 90, (30+31+30)=91
    A partir de juillet, (31+31+30)=92 et pour le 4T,(31+30+31)=92
    L’année bissextile me pose problème

    Et tout ça si le paiement se fait par trimestre mais si le « paiement » de la table loyers se fait par mois, on divise seuelement par 12 le nouveau loyer à partir du mois revisé

    De plus, j’aimerai egalement que si la date de fin de la table loyer est depassé alors plus de loyer.

    Je sais pas si j’ai été clair mais voila mon probleme
    Fichiers attachés Fichiers attachés

Discussions similaires

  1. probleme requete
    Par voyageur dans le forum PostgreSQL
    Réponses: 6
    Dernier message: 06/11/2004, 21h43
  2. Réponses: 3
    Dernier message: 17/05/2004, 17h28
  3. [langage] problème avec fonction read
    Par domidum54 dans le forum Langage
    Réponses: 2
    Dernier message: 30/03/2004, 20h42
  4. [VB6]Problème de fonction
    Par mustang-ffw02 dans le forum VB 6 et antérieur
    Réponses: 13
    Dernier message: 27/03/2004, 15h09
  5. Probleme de fonction
    Par yenna dans le forum ASP
    Réponses: 6
    Dernier message: 01/03/2004, 14h10

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo