Partage
  • Partager sur Facebook
  • Partager sur Twitter

[SQL] Petit Correctif Rapide

Sujet résolu
    9 avril 2011 à 13:12:00

    Bonjour,

    Voilà, la requête est opérationnel, jusque la, rien à dire.. Sauf que celle ci n'affiche pas correctement dans l'ordre désiré, ce qui pose un petit soucis mineur qui pourrais être corrigé.

    SELECT *,
    (SELECT COUNT(DISTINCT b.level) FROM player AS b WHERE b.level >= a.level AND name NOT IN(SELECT mName FROM common.gmlist), 
    (SELECT COUNT(DISTINCT b.exp) FROM player AS b WHERE b.exp >= a.exp AND name NOT IN(SELECT mName FROM common.gmlist)))
    AS 'position' FROM player AS a WHERE name NOT IN(SELECT mName FROM common.gmlist) ORDER BY position ASC, level DESC, exp DESC
    


    Donc le but, est de récupèrer les "Level" et "EXP" de chaques joueurs, qui en mm temps compare dans la liste des GM si celui-ci en est pas un, pour ne pas le comptabilisé.. Qui au final classe par Position, pour afficher dans le classement, lors d'une recherche ou autres le Rang vis à vis des autres joueurs.

    Sauf que le soucis, c'est qu'il classe bien selon le "LEVEL" et l'EXP, sauf que la position pour certains est identique, soit :
    Joueur 1 : Level 5, EXP 9854
    Joueur 2 : Level 2, EXP 4587
    Joueur 3 : Level 2, EXP 4521
    Joueur 4 : Level 1, EXP 8745

    Le classement va retourner les valeur suivant :
    # Rang     Pseudo         Level    EXP
      1        Joueur1        5        9854
      2        Joueur2        2        4587
      2        Joueur3        2        4521
      3        Joueur4        1        8745


    Merci d'éclairer ma lanterne quelques peu atténuer par cette requête étrange en soit.
    • Partager sur Facebook
    • Partager sur Twitter
    Anonyme
      9 avril 2011 à 13:25:48

      Bonjour,
      voila qui parait bien compliqué, mais pourais tu nous donner tes structures de tables , merci
      • Partager sur Facebook
      • Partager sur Twitter
        9 avril 2011 à 13:40:40

        Bonjour, voici les structures demandés :

        Player :
        CREATE TABLE IF NOT EXISTS `player` (
          `id` int(11) NOT NULL AUTO_INCREMENT,
          `account_id` int(11) NOT NULL DEFAULT '0',
          `name` varchar(24) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'NONAME',
          `job` tinyint(2) unsigned NOT NULL DEFAULT '0',
          `voice` tinyint(1) unsigned NOT NULL DEFAULT '0',
          `dir` tinyint(2) NOT NULL DEFAULT '0',
          `x` int(11) NOT NULL DEFAULT '0',
          `y` int(11) NOT NULL DEFAULT '0',
          `z` int(11) NOT NULL DEFAULT '0',
          `map_index` int(11) NOT NULL DEFAULT '0',
          `exit_x` int(11) NOT NULL DEFAULT '0',
          `exit_y` int(11) NOT NULL DEFAULT '0',
          `exit_map_index` int(11) NOT NULL DEFAULT '0',
          `hp` smallint(4) NOT NULL DEFAULT '0',
          `mp` smallint(4) NOT NULL DEFAULT '0',
          `stamina` smallint(6) NOT NULL DEFAULT '0',
          `random_hp` smallint(5) unsigned NOT NULL DEFAULT '0',
          `random_sp` smallint(5) unsigned NOT NULL DEFAULT '0',
          `playtime` int(11) NOT NULL DEFAULT '0',
          `level` tinyint(2) unsigned NOT NULL DEFAULT '1',
          `level_step` tinyint(1) NOT NULL DEFAULT '0',
          `st` smallint(3) NOT NULL DEFAULT '0',
          `ht` smallint(3) NOT NULL DEFAULT '0',
          `dx` smallint(3) NOT NULL DEFAULT '0',
          `iq` smallint(3) NOT NULL DEFAULT '0',
          `exp` int(11) NOT NULL DEFAULT '0',
          `gold` int(11) NOT NULL DEFAULT '0',
          `stat_point` smallint(3) NOT NULL DEFAULT '0',
          `skill_point` smallint(3) NOT NULL DEFAULT '0',
          `quickslot` tinyblob,
          `ip` varchar(15) COLLATE utf8_unicode_ci DEFAULT '0.0.0.0',
          `part_main` smallint(6) NOT NULL DEFAULT '0',
          `part_base` tinyint(4) NOT NULL DEFAULT '0',
          `part_hair` smallint(4) NOT NULL DEFAULT '0',
          `skill_group` tinyint(4) NOT NULL DEFAULT '0',
          `skill_level` blob,
          `alignment` int(11) NOT NULL DEFAULT '0',
          `last_play` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
          `change_name` tinyint(1) NOT NULL DEFAULT '0',
          `mobile` varchar(24) COLLATE utf8_unicode_ci DEFAULT NULL,
          `sub_skill_point` smallint(3) NOT NULL DEFAULT '0',
          `stat_reset_count` tinyint(4) NOT NULL DEFAULT '0',
          `horse_hp` smallint(4) NOT NULL DEFAULT '0',
          `horse_stamina` smallint(4) NOT NULL DEFAULT '0',
          `horse_level` tinyint(2) unsigned NOT NULL DEFAULT '0',
          `horse_hp_droptime` int(10) unsigned NOT NULL DEFAULT '0',
          `horse_riding` tinyint(1) NOT NULL DEFAULT '0',
          `horse_skill_point` smallint(3) NOT NULL DEFAULT '0',
          PRIMARY KEY (`id`),
          UNIQUE KEY `name` (`name`),
          KEY `account_id_idx` (`account_id`)
        ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=6 ;
        


        GmLIST :
        CREATE TABLE IF NOT EXISTS `gmlist` (
          `mID` int(10) unsigned NOT NULL AUTO_INCREMENT,
          `mAccount` varchar(32) NOT NULL DEFAULT '',
          `mName` varchar(32) NOT NULL DEFAULT '',
          `mContactIP` varchar(16) NOT NULL DEFAULT '',
          `mServerIP` varchar(16) NOT NULL DEFAULT 'ALL',
          `mAuthority` enum('IMPLEMENTOR','HIGH_WIZARD','GOD','LOW_WIZARD','PLAYER') DEFAULT 'PLAYER',
          PRIMARY KEY (`mID`)
        ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=34 ;
        
        • Partager sur Facebook
        • Partager sur Twitter
        Anonyme
          9 avril 2011 à 14:39:58

          Je n'arrives pas a m'en sortir, escuses moi, je regardes encore et reviens dés que j'ais une idée :honte:
          • Partager sur Facebook
          • Partager sur Twitter
            9 avril 2011 à 14:45:10

            Slt, j'essaie également de comprendre ou de trouver le bug dans ta requête.
            Personnellement, j'aurais plutôt posté dans cette rubrique ==> http://www.siteduzero.com/forum-81-406 [...] -donnees.html

            lemirandais
            • Partager sur Facebook
            • Partager sur Twitter
            Dommage, impossible de mettre ma signature
              9 avril 2011 à 15:25:56

              Un jeu d'essai serait la bienvenue mais d'emblée, je dirais que cette requête fonctionne

              SELECT *, (SELECT DISTINCT COUNT(*) FROM player p2 WHERE (p2.level > p1.level) OR (p1.level <= p2.level AND p2.exp >= p1.exp) ) AS position
              FROM player p1
              WHERE name NOT IN(SELECT mName FROM gmlist)
              ORDER BY position
              
              • Partager sur Facebook
              • Partager sur Twitter
              Anonyme
                9 avril 2011 à 16:40:58

                On en apprend tout les jours, cette forme avec un SELECT COUNT imbriqué j'avais jamais pratiqué !
                Je notes :)
                • Partager sur Facebook
                • Partager sur Twitter
                  9 avril 2011 à 17:11:56

                  Merci beaucoup de votre aide, ta réponse Zazou était en partie correcte, je l'ai juste paufiner à ma sauce, histoire d'être sur que tout fonctionne comme je le désire. Maintenant c'est impec! Merci beaucoup!
                  • Partager sur Facebook
                  • Partager sur Twitter

                  [SQL] Petit Correctif Rapide

                  × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
                  × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
                  • Editeur
                  • Markdown