🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: es.comp.os.linux.programacion
Article #11433

Dos dudas sobre SQL.

#11433
From: Jesús Carrete Montaña
Date: Sat, 01 Dec 2001 19:08
53 lines
3463 bytes
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


Buenas.
        Estoy empezando a ponerme en SQL (con mySQL,
concretamente). Tengo la base de datos oposiciones2001, con las
siguientes tres tablas:
mysql> DESCRIBE opositores;
+-----------+--------------------------+------+-----+---------+-------+
| Field     | Type                     | Null | Key | Default | Extra |
+-----------+--------------------------+------+-----+---------+-------+
| dni       | int(8) unsigned zerofill | YES  |     | NULL    |       |
| nombre    | varchar(100)             | YES  |     | NULL    |       |
| apellidos | varchar(100)             | YES  |     | NULL    |       |
| turno     | char(1)                  | YES  |     | NULL    |       |
+-----------+--------------------------+------+-----+---------+-------+
mysql> DESCRIBE examen1;
+-------+--------------------------+------+-----+---------+-------+
| Field | Type                     | Null | Key | Default | Extra |
+-------+--------------------------+------+-----+---------+-------+
| dni   | int(8) unsigned zerofill | YES  |     | NULL    |       |
| nota  | decimal(5,3) unsigned    | YES  |     | NULL    |       |
+-------+--------------------------+------+-----+---------+-------+
Y examen2 que es igual que examen1. opositores y examen1 tienen 6498
registros, mientras que examen2 tiene 1903.

Pues bien, las dos preguntas son:

a) �C�mo puedo formular un SELECT de forma que me muestre dos
columnas: nombre y nota, de aquellos individuos que han sacado m�s nota que la
media en el primer examen? Teniendo en cuenta que mysql no acepta un
SELECT dentro de otro, AFAIK.

b) Si ejecuto la siguiente sentencia:
SELECT o.nombre, (e1.nota + e2.nota) AS notatotal FROM opositores o,
examen1 e1, examen2 e2 WHERE o.dni = e1.dni AND e1.dni = e2.dni;
        Tarda much�simo, de hecho tarda tanto que no tengo paciencia
para esperar XD. Seguro que estoy haciendo alguna burrada gord�sima y
se puede formular de una manera m�s eficiente.

Un saludo y gracias de antemano a quien me pueda ayudar.
- -- 
Tux of Borg to MSian ship: Prepare to be dominated. Marketing is
futile. PR is irrelevant.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.6 <http://mailcrypt.sourceforge.net/>

iD8DBQE8CSp2fUtQQKOnZ1IRAnqYAJ92hW8LIP2BrXU4Wticej2SkW44HwCfZ3qt
nYPNuF69K9sUjFPI6y2uLCM=
=gKqI
-----END PGP SIGNATURE-----
Technical Details
Message-ID: <87g06u69nh.fsf@meltdown.ion>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!news.tele.dk!small.news.tele.dk!130.133.1.3!fu-berlin.de!uni-berlin.de!213.98.91.117!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: SPANISH,ASCII
X-Google-Thread: f86c8,b998237532da112b,start
X-Google-Attributes: gidf86c8,public
X-Google-ArrivalTime: 2001-12-01 12:20:18 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!news.tele.dk!small.news.tele.dk!130.133.1.3!fu-berlin.de!uni-berlin.de!213.98.91.117!not-for-mail
From: kuantiko@escomposlinux.org (Jesús Carrete
  Montaña)
Newsgroups: es.comp.os.linux.programacion
Subject: Dos dudas sobre SQL.
Date: 01 Dec 2001 20:08:18 +0100
Organization: ecolnet
Lines: 53
Sender: kuantiko@meltdown.ion
Message-ID: <87g06u69nh.fsf@meltdown.ion>
NNTP-Posting-Host: 213.98.91.117
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
X-Trace: fu-berlin.de 1007238015 7761582 213.98.91.117 (16 [63420])
X-Orig-Path: julieta.escomposlinux.net!antonio.escomposlinux.net!relativistic.homeip.net!nobody
User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7