|
|
|
|
 |
|  |
 |
Simone_155 |
| [AIUTO!!!] Query SQL |
01-07-2007 17:57 |
|
 |
Simone_155 |
Like a Great White Shark

Registered: Mar 2006
Posts: 140 (0.02 al dì)
Location: Piacenza
Corso: Informatica
Anno: 3
Time Online: 1 Day, 2:30:23 [...]
Status: Offline
Edit | Report | IP: Logged |
[AIUTO!!!] Query SQL
Aiuto, ho una query SQL che non ho idea di come trattare!Qualcuno mi saprebbe spiegare come si fa??è quella del tema di Gennaio 2006.
Eccol la base di dati:
VENDITA (CodVend,CodCli,CodProd,Qta)
VENDITORE (Codice,Nome,Città)
CLIENTE (CodiceCli,NomeCli,CittàCli)
La query è la seguente:
Determinare il venditore di Verona che ha venduto la maggior quantità complessiva di prodotti nella base di dati.
Io l'ho fatta così, ma non credo sia giusta...
SELECT V.Nome,V.Codice,max(maxVend.totVend)
FROM (VENDITORE AS V INNER JOIN (SELECT SUM(Qta) AS totVend FROM VENDITA GROUP BY CodVend) AS maxVend ON V.Codice = maxVend.CodVend) WHERE Città = 'Verona'
Help please...perchè nei compiti di basi di query simili ce ne sono un sacco, e io non so proprio come risolverle!!!!
HEEEEEELLLLPPPPP
__________________
"There is a creature alive today who has survived millions of years of evolution without change, without passion, and without logic. It lives to kill. A mindless eating machine, it will attack and devour anything. It is as though God created the devil and gave him jaws."
- From the preview for 'JAWS' - 1975
|
|
01-07-2007 17:57 |
|
|
|  |
 |
seba01 |
| Ciao, questa query dovrebbe funzionare, non so se ... |
03-07-2007 13:33 |
|
 |
seba01 |
.simpatizzante.
Registered: Jan 2003
Posts: 10 (0.00 al dì)
Location: milano
Corso: informatica
Anno: 3
Time Online: 22:02:10 [...]
Status: Offline
Edit | Report | IP: Logged |
Ciao, questa query dovrebbe funzionare, non so se è la migliore possibile...
In pratica la prima parte si occupa di selezionare i record dei venditori di verona con le quantità totali di prodotti venduti,
mentre la seconda mi fornisce la massima quantità dei prodotti venduti da un venditore.
Mettendo in join le due ottieni quanto richiesto.
select codVend from (select codVend,sum(Qta) as QtaTot from VENDITA,Venditore
where codVend = Codice and Venditore.Citta = 'Verona'
group by codVend)as ListaVend,
(select max(qtatot)as mass from(select sum(Qta) as QtaTot from VENDITA,Venditore
where codVend = Codice and Venditore.Citta = 'Verona'
group by codVend) as res) as Massimo
where Massimo.mass = ListaVend.qtatot
|
|
03-07-2007 13:33 |
|
|
|  |
 |
Simone_155 |
| Mamma mia, tripla JOIN??
... |
03-07-2007 14:46 |
|
 |
Simone_155 |
Like a Great White Shark

Registered: Mar 2006
Posts: 140 (0.02 al dì)
Location: Piacenza
Corso: Informatica
Anno: 3
Time Online: 1 Day, 2:30:23 [...]
Status: Offline
Edit | Report | IP: Logged |
Mamma mia, tripla JOIN??
Mah, magari è giusta, però penso che si possa fare in maniera innestata...ma non riesco a trovare il modo di farla...ma quanto c***o è difficile???
__________________
"There is a creature alive today who has survived millions of years of evolution without change, without passion, and without logic. It lives to kill. A mindless eating machine, it will attack and devour anything. It is as though God created the devil and gave him jaws."
- From the preview for 'JAWS' - 1975
|
|
03-07-2007 14:46 |
|
|
|  |
 |
seba01 |
| bhe cosi' è innestata, ma credo cambi poco in ter ... |
05-07-2007 10:02 |
|
 |
seba01 |
.simpatizzante.
Registered: Jan 2003
Posts: 10 (0.00 al dì)
Location: milano
Corso: informatica
Anno: 3
Time Online: 22:02:10 [...]
Status: Offline
Edit | Report | IP: Logged |
bhe cosi' è innestata, ma credo cambi poco in termini di elaborazione rispetto a quella col join....
select codVend from (select codVend,sum(Qta) as QtaTot from VENDITA,Venditore
where codVend = Codice and Venditore.Citta = 'Verona'
group by codVend) ListaVend
where QtaTot =
(select max(qtatot)as mass from(select sum(Qta) as QtaTot from VENDITA,Venditore
where codVend = Codice and Venditore.Citta = 'Verona'
group by codVend) res)
|
|
05-07-2007 10:02 |
|
|
|  |
 |
Simone_155 |
| Allora, dopo averla rifatta per l'ennesima volta a ... |
05-07-2007 11:18 |
|
 |
Simone_155 |
Like a Great White Shark

Registered: Mar 2006
Posts: 140 (0.02 al dì)
Location: Piacenza
Corso: Informatica
Anno: 3
Time Online: 1 Day, 2:30:23 [...]
Status: Offline
Edit | Report | IP: Logged |
Allora, dopo averla rifatta per l'ennesima volta assieme ad un mio compagno (bella Ivan!!!!!), è saltata fuori sta cosa che mi piace anche abbastanza:
SELECT CodVend,Nome
FROM VENDITA JOIN VENDITORE ON codVend = Codice
WHERE Città = 'Verona'
GROUP BY CodVend,Nome
HAVING SUM(Qta) >= ALL (SELECT SUM(Qta)
FROM VENDITA
GROUP BY CodVend)
Dovrebbe andare no?
__________________
"There is a creature alive today who has survived millions of years of evolution without change, without passion, and without logic. It lives to kill. A mindless eating machine, it will attack and devour anything. It is as though God created the devil and gave him jaws."
- From the preview for 'JAWS' - 1975
|
|
05-07-2007 11:18 |
|
|
|  |
 |
| All times are GMT. The time now is 09:45. |
|
|
 |
|
 |
|
|
|  |
Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is ON
|
|
|
|
|
|