.dsy:it.
Show 150 posts per page

.dsy:it. (http://www.dsy.it/forum/)
- Basi di dati ~ informatica triennale (http://www.dsy.it/forum/forumdisplay.php?forumid=211)
-- [AIUTO!!!] Query SQL (http://www.dsy.it/forum/showthread.php?threadid=31356)


Posted by Simone_155 on 01-07-2007 17:57:

[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


Posted by seba01 on 03-07-2007 13:33:

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


Posted by Simone_155 on 03-07-2007 14:46:

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


Posted by seba01 on 05-07-2007 10:02:

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)


Posted by Simone_155 on 05-07-2007 11:18:

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


All times are GMT. The time now is 22:07.
Show all 5 posts from this thread on one page

Powered by: vBulletin Version 2.3.1
Copyright © Jelsoft Enterprises Limited 2000 - 2002.