Dsy Network www | forum | my | didattica | howto | wiki | el goog | stats | blog | dona | rappresentanti
Homepage
 Register   Calendar   Members  Faq   Search  Logout 
.dsy:it. : Powered by vBulletin version 2.3.1 .dsy:it. > Didattica > Corsi A - F > Basi di dati ~ informatica triennale > [AIUTO!!!] Query SQL
  Last Thread   Next Thread
Author
Thread    Expand all | Contract all    Post New Thread    Post A Reply
Collapse
Simone_155
Like a Great White Shark

User info:
Registered: Mar 2006
Posts: 140 (0.02 al dì)
Location: Piacenza
Corso: Informatica
Anno: 3
Time Online: 1 Day, 2:30:23 [...]
Status: Offline

Post actions:

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
Click Here to See the Profile for Simone_155 Click here to Send Simone_155 a Private Message Find more posts by Simone_155 Add Simone_155 to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
seba01
.simpatizzante.

User info:
Registered: Jan 2003
Posts: 10 (0.00 al dì)
Location: milano
Corso: informatica
Anno: 3
Time Online: 22:02:10 [...]
Status: Offline

Post actions:

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
Click Here to See the Profile for seba01 Click here to Send seba01 a Private Message Find more posts by seba01 Add seba01 to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
Simone_155
Like a Great White Shark

User info:
Registered: Mar 2006
Posts: 140 (0.02 al dì)
Location: Piacenza
Corso: Informatica
Anno: 3
Time Online: 1 Day, 2:30:23 [...]
Status: Offline

Post actions:

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
Click Here to See the Profile for Simone_155 Click here to Send Simone_155 a Private Message Find more posts by Simone_155 Add Simone_155 to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
seba01
.simpatizzante.

User info:
Registered: Jan 2003
Posts: 10 (0.00 al dì)
Location: milano
Corso: informatica
Anno: 3
Time Online: 22:02:10 [...]
Status: Offline

Post actions:

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
Click Here to See the Profile for seba01 Click here to Send seba01 a Private Message Find more posts by seba01 Add seba01 to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
Simone_155
Like a Great White Shark

User info:
Registered: Mar 2006
Posts: 140 (0.02 al dì)
Location: Piacenza
Corso: Informatica
Anno: 3
Time Online: 1 Day, 2:30:23 [...]
Status: Offline

Post actions:

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
Click Here to See the Profile for Simone_155 Click here to Send Simone_155 a Private Message Find more posts by Simone_155 Add Simone_155 to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
All times are GMT. The time now is 09:45.    Post New Thread    Post A Reply
  Last Thread   Next Thread
Show Printable Version | Email this Page | Subscribe to this Thread | Add to Bookmarks

Forum Jump:
Rate This Thread:

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
 

Powered by: vBulletin v2.3.1 - Copyright ©2000 - 2002, Jelsoft Enterprises Limited
Mantained by dsy crew (email) | Collabora con noi | Segnalaci un bug | Archive | Regolamento | Licenze | Thanks | Syndacate
Pagina generata in 0.107 seconds (58.27% PHP - 41.73% MySQL) con 26 query.