Visualizzazione dei risultati da 1 a 5 su 5
  1. #1
    Utente di HTML.it
    Registrato dal
    Oct 2010
    Messaggi
    21

    query più tabelle

    Salve ragazzi avrei bisogno di un aiuto.
    Ho un database che voglio interrogare per mettere in relazione più dati.
    In questo database ho molte tabelle ma di cui 2 mi interessano veramente,il db in questione raccoglie dei risultati di corse automobilistiche e genera un rank (ringrazio un utente di questo sito che ha fatto un gran lavoro ).
    Ora io ho 2 tabelle (risultati e sistema punteggio) nella prima ho le seguenti colonne:
    IDPilota,IDCampionato e i vari campionati nella seconda tabella (sist. punteggio ho) IDCampionato , IDPunteggio (in pratica la prima mette in relazione i piloti con i campionati in cui corrono e i rispettivi risultati,la seconda relaziona i campionati e i punteggi).

    Nello script che uso ora metto in relazione i vari dati rispetto all'IDPilota,io vorrei fare in modo di mettere in relazione IDpilota con IDCampionato con IDpunteggio cioè se il pilota corre in un campionato con un determinato punteggio prende tot punti altrimenti prende un punteggio diverso.
    Qualche buon anima mi può aiutare?

    saluto luigi,un grande

  2. #2
    Utente di HTML.it L'avatar di nicola75ss
    Registrato dal
    Nov 2004
    Messaggi
    12,922
    Specifica su quale database stai lavorando, in maniera che possa includerlo nel titolo e spostare la discussione nell'apposita sezione.

    Se poi posti un dump delle tabelle sarà più facile aiutarti.

  3. #3
    Utente di HTML.it
    Registrato dal
    Oct 2010
    Messaggi
    21
    tabella 1


    CREATE TABLE IF NOT EXISTS `gpcos_tblseason` (
    `id` int(10) unsigned NOT NULL auto_increment,
    `Name` varchar(15) default NULL,
    `SeasonIntroduction` text,
    `SeasonReport` text,
    `LeagueID` smallint(5) unsigned default '0',
    `ChampionDriverID` smallint(5) unsigned default '0',
    `ChampionTeamID` smallint(5) unsigned default '0',
    `RunnerUpDriverID` smallint(5) unsigned default NULL,
    `RunnerUpTeamID` smallint(5) unsigned default NULL,
    `StartDate` date default NULL,
    `EndDate` date default NULL,
    `ClosedDate` datetime default NULL,
    `SeasonFinished` enum('Yes','No') NOT NULL default 'No',
    `DiscardedEvents` tinyint(3) unsigned default '0',
    `MultipleGroups` enum('Yes','No') NOT NULL default 'No',
    PRIMARY KEY (`id`),
    UNIQUE KEY `id` (`id`),
    KEY `id_2` (`id`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=11 ;


    tabella 2


    CREATE TABLE IF NOT EXISTS `gpcos_tblpointdistribution` (
    `id` int(10) unsigned NOT NULL auto_increment,
    `LeagueID` smallint(5) unsigned default NULL,
    `PointDistribution` varchar(40) NOT NULL default 'Default',
    `LL` tinyint(3) default '0',
    `MLL` tinyint(3) default '0',
    `LastUpdate` datetime default NULL,


    Io vorrei mettere in relazione-driverid-leagueID (tabella1 )con leagueID--Pointdistribution (tabella2)
    per esempio ora una query base è count(rpos) form tab1 where DriverID row id AND rpos=1

    io vorrei includere nella query anche le variabili LeagueID e in base al valore PointDistribution

    cioè poter dire in definitiva che il valore della query mostrata prima vale tot se c'è un certo valore nella colonna PointDistribuition.

  4. #4
    Utente di HTML.it L'avatar di nicola75ss
    Registrato dal
    Nov 2004
    Messaggi
    12,922
    Hai dimenticato un pezzo di tabella2.

    Posta anche il dump di popolamento delle due tabelle.

  5. #5
    Utente di HTML.it
    Registrato dal
    Oct 2010
    Messaggi
    21
    spero vada bene così (non sono molto pratico ancora),la tabella 2 è incompleta perchè per non occupare spazio inutilmente ho cancellato delle colonne che non servono,sono 60 colonne
    Tab1

    codice:
    -- phpMyAdmin SQL Dump
    -- version 3.3.8
    -- http://www.phpmyadmin.net
    --
    -- Host: localhost
    -- Generato il: 31 ott, 2010 at 07:35 PM
    -- Versione MySQL: 5.0.51
    -- Versione PHP: 5.2.14
    
    SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
    
    
    /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
    /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
    /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
    /*!40101 SET NAMES utf8 */;
    
    --
    -- Database: `iraceonl_gpcos`
    --
    
    -- --------------------------------------------------------
    
    --
    -- Struttura della tabella `gpcos_tblresults`
    --
    
    DROP TABLE IF EXISTS `gpcos_tblresults`;
    CREATE TABLE IF NOT EXISTS `gpcos_tblresults` (
      `id` int(10) unsigned NOT NULL auto_increment,
      `DriverID` smallint(5) unsigned default '0',
      `TeamID` smallint(5) unsigned default '0',
      `EventID` int(10) unsigned default '0',
      `TrackID` smallint(5) unsigned default NULL,
      `LeagueID` smallint(5) unsigned default NULL,
      `DriverIP` varchar(15) default '0',
      `CarModelID` tinyint(3) unsigned default NULL,
      `CarClass` varchar(25) default NULL,
      `StartNumber` tinyint(3) unsigned default '0',
      `QTime` mediumint(8) unsigned default NULL,
      `QPos` smallint(5) unsigned default '0',
      `QPosOverall` smallint(5) unsigned default NULL,
      `QLaps` smallint(5) unsigned default NULL,
      `RTime` int(10) default NULL,
      `RLaps` smallint(5) unsigned default '0',
      `RFastestLap` mediumint(8) unsigned default NULL,
      `FL_Indication` enum('1','0') NOT NULL default '0',
      `LeadLaps` smallint(6) NOT NULL default '0',
      `LL_Indication` enum('1','0') NOT NULL default '0',
      `MLL_Indication` enum('1','0') NOT NULL default '0',
      `RPos` smallint(5) unsigned default '0',
      `RPosOverall` smallint(5) unsigned default NULL,
      `Pitstops` tinyint(3) unsigned default NULL,
      `QPoints` smallint(2) unsigned default NULL,
      `RPoints` smallint(2) unsigned default NULL,
      `FLPoints` smallint(2) unsigned default '0',
      `LLPoints` smallint(2) NOT NULL default '0',
      `MLLPoints` smallint(2) NOT NULL default '0',
      `PPoints` smallint(2) unsigned default '0',
      `TPoints` smallint(2) default NULL,
      `PenaltyID` tinyint(1) unsigned default NULL,
      `QFinishStatusID` tinyint(3) unsigned default NULL,
      `RFinishStatusID` tinyint(3) unsigned default NULL,
      `DNFReason` varchar(50) default NULL,
      `ResultEdited` enum('1','0') default '0',
      `Date` datetime default NULL,
      PRIMARY KEY  (`id`),
      UNIQUE KEY `id` (`id`),
      KEY `id_2` (`id`),
      KEY `EventLeague` (`EventID`,`LeagueID`),
      KEY `EventDriver` (`DriverID`,`EventID`),
      KEY `DriverPoints` (`DriverID`,`EventID`,`LeagueID`,`TPoints`),
      KEY `TeamPoints` (`EventID`,`LeagueID`,`TeamID`,`TPoints`)
    ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1117 ;
    
    --
    -- Dump dei dati per la tabella `gpcos_tblresults`
    --
    
    INSERT INTO `gpcos_tblresults` VALUES(764, 76, 17, 31, 15, 6, '-', 1, 'BMW 320si E90', 0, 0, 12, 12, 0, 0, 1, 157145, '0', 0, '0', '0', 25, 25, 1, 0, 0, 0, 0, 0, 0, 0, NULL, 3, 2, 'DNF', '0', '2010-10-04 19:23:02');
    tab2

    codice:
    -- phpMyAdmin SQL Dump
    -- version 3.3.8
    -- http://www.phpmyadmin.net
    --
    -- Host: localhost
    -- Generato il: 31 ott, 2010 at 06:18 PM
    -- Versione MySQL: 5.0.51
    -- Versione PHP: 5.2.14
    
    SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
    
    
    /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
    /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
    /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
    /*!40101 SET NAMES utf8 */;
    
    --
    -- Database: `iraceonl_gpcos`
    --
    
    -- --------------------------------------------------------
    
    --
    -- Struttura della tabella `gpcos_tblpointdistribution`
    --
    
    DROP TABLE IF EXISTS `gpcos_tblpointdistribution`;
    CREATE TABLE IF NOT EXISTS `gpcos_tblpointdistribution` (
      `id` int(10) unsigned NOT NULL auto_increment,
      `LeagueID` smallint(5) unsigned default NULL,
      `PointDistribution` varchar(40) NOT NULL default 'Default',
      `FL` tinyint(3) unsigned default '0',
      `LL` tinyint(3) default '0',
      `MLL` tinyint(3) default '0',
      `LastUpdate` datetime default NULL,
      PRIMARY KEY  (`id`),
      UNIQUE KEY `id` (`id`),
      KEY `id_2` (`id`)
    ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=11 ;
    
    --
    -- Dump dei dati per la tabella `gpcos_tblpointdistribution`
    --
    
    INSERT INTO `gpcos_tblpointdistribution` VALUES(1, 2, 'IRon SE', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25, 18, 15, 12, 10, 8, 6, 4, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '2010-08-10 21:00:53');
    INSERT INTO `gpcos_tblpointdistribution` VALUES(4, 6, 'IRON_C', 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25, 18, 15, 12, 10, 8, 6, 4, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, '2010-10-31 00:13:19');
    INSERT INTO `gpcos_tblpointdistribution` VALUES(8, 9, 'IRON_B', 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 13, 10, 8, 6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, '2010-10-31 00:14:36');
    INSERT INTO `gpcos_tblpointdistribution` VALUES(6, 8, 'IRON_A', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25, 18, 15, 12, 10, 8, 6, 4, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '2010-10-31 00:13:45');

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.