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!] Sql
  Last Thread   Next Thread
Author
Thread    Expand all | Contract all    Post New Thread    Post A Reply
Collapse
ste182
.arcimaestro.

User info:
Registered: Oct 2004
Posts: 258 (0.03 al dì)
Location:
Corso: informatica
Anno:
Time Online: 2 Days, 5:06:07: [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged
[aiuto!] Sql

ciao ragazzi, voi come risolvereste questo esercizio?
Vendita(CodVend,CodCli,CodProd,Qta)
Venditore(Codice,Nome,Città')
Cliente(CodiceCli,NomeCli,CittàCli)

determinare il venditore di Verona che ha venduto la maggior quantità complessiva di prodotti nella base di dati..

io ho pensato di fare la somma delle Qta raggruppandoli per CodVend così:
SELECT SUM(Qta)
FROM Vendita
GROUP by CodVend
così ricavo una tabella con la somma delle quantità per ogni venditore(CodVend).. poi però come faccio a prendere solo il venditore di verona con il max di quantità venduta???

__________________
Live Fast, Die Fun

16-01-2009 15:09
Click Here to See the Profile for ste182 Click here to Send ste182 a Private Message Find more posts by ste182 Add ste182 to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
gae84
.illuminato.

User info:
Registered: Jun 2005
Posts: 226 (0.03 al dì)
Location: Cesano Boscone
Corso: comunicazione digitale
Anno: sempre più fuori corso
Time Online: 16 Days, 14:49:51 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

penso sia così, anche se magari c'è qualke errore..... come idea generale cmq devi dirgli di ritornare il venditore per il quale nn ci sono altri venditori con vendite personali maggiori alle sue, oppure, detto in altra maniera, devi trovare il venditore che ha venduto una quantità di articoli maggiore di tutte le altre vendite personali all'interno del database

SELECT CodVend AS cod, SUM(QTA) AS tot FROM Vendita WHERE CodVend=cod AND SUM(QTA) > ALL (
SELECT SUM(QTA) FROm Vendita GROUP BY CodVend
)

16-01-2009 15:36
Click Here to See the Profile for gae84 Click here to Send gae84 a Private Message Find more posts by gae84 Add gae84 to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
ste182
.arcimaestro.

User info:
Registered: Oct 2004
Posts: 258 (0.03 al dì)
Location:
Corso: informatica
Anno:
Time Online: 2 Days, 5:06:07: [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Originally posted by gae84
penso sia così, anche se magari c'è qualke errore..... come idea generale cmq devi dirgli di ritornare il venditore per il quale nn ci sono altri venditori con vendite personali maggiori alle sue, oppure, detto in altra maniera, devi trovare il venditore che ha venduto una quantità di articoli maggiore di tutte le altre vendite personali all'interno del database

SELECT CodVend AS cod, SUM(QTA) AS tot FROM Vendita WHERE CodVend=cod AND SUM(QTA) > ALL (
SELECT SUM(QTA) FROm Vendita GROUP BY CodVend
)

non capisco la condizione WHERE CodVend=cod
cod l'hai definito da CodVend quindi sarà sempre uguale... no?

__________________
Live Fast, Die Fun

16-01-2009 15:52
Click Here to See the Profile for ste182 Click here to Send ste182 a Private Message Find more posts by ste182 Add ste182 to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
ste182
.arcimaestro.

User info:
Registered: Oct 2004
Posts: 258 (0.03 al dì)
Location:
Corso: informatica
Anno:
Time Online: 2 Days, 5:06:07: [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

ho pensato di fare così, ditemi se può funzionare:

SELECT CodVend as Codice, SUM(Qta) as Totale
FROM Vendita
WHERE CodVend in
(
SELECT Codice as CodVend, SUM(Qta)
FROM Venditore, Vendita
WHERE Città= "Verona" AND SUM(Qta) > ALL (SELECT SUM(Qta) FROM VENDITA GROUP by CodVend)
)

__________________
Live Fast, Die Fun

16-01-2009 16:11
Click Here to See the Profile for ste182 Click here to Send ste182 a Private Message Find more posts by ste182 Add ste182 to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
ste182
.arcimaestro.

User info:
Registered: Oct 2004
Posts: 258 (0.03 al dì)
Location:
Corso: informatica
Anno:
Time Online: 2 Days, 5:06:07: [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

oppure meglio questo:

SELECT Codice
FROM Venditore INNER JOIN Vendita ON Codice=CodVend
WHERE Venditore.Città="Verona" AND Qta = MAX(SELECT SUM(Qta) FROM Vendita GROUP by CodVend)

che dite?? sto sparando solo cavolate o potrebbe avere senso??:?:D

__________________
Live Fast, Die Fun

16-01-2009 17:34
Click Here to See the Profile for ste182 Click here to Send ste182 a Private Message Find more posts by ste182 Add ste182 to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
ste182
.arcimaestro.

User info:
Registered: Oct 2004
Posts: 258 (0.03 al dì)
Location:
Corso: informatica
Anno:
Time Online: 2 Days, 5:06:07: [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

ennò cavoli non và bene.. ragazzi aiutoooooooooooooo!!

__________________
Live Fast, Die Fun

16-01-2009 17:39
Click Here to See the Profile for ste182 Click here to Send ste182 a Private Message Find more posts by ste182 Add ste182 to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
Counter65
.illuminato.

User info:
Registered: Sep 2008
Posts: 180 (0.03 al dì)
Location:
Corso:
Anno:
Time Online: 1 Day, 13:15:27 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

SELECT CodVend AS cod, SUM(QTA) AS tot FROM Vendita WHERE CodVend=cod AND SUM(QTA) >= ALL (
SELECT SUM(QTA) FROm Vendita GROUP BY CodVend
)

quello che ha scritto gae è giusto manca solo l'uguale dopo il maggiore

16-01-2009 20:37
Click Here to See the Profile for Counter65 Click here to Send Counter65 a Private Message Find more posts by Counter65 Add Counter65 to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
morte2097
.primate.

User info:
Registered: Sep 2004
Posts: 68 (0.01 al dì)
Location: --------------------------------
Corso: info
Anno: primo
Time Online: 1 Day, 14:12:29 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

scusa non vorrei dire una cavolata ma sum(qta) >=all dovresti porlo nell'having non nel where e poi devi confrontarli con quelli della città di verona , secondo me sarebbe

SELECT Vendita.CodVend , SUM(Qta)
FROM Vendita,Venditore
WHERE Vendita.CodVend = Venditore.Codice AND
Venditore.città= "verona"
GROUP BY Vendita.CodVend
HAVING SUM(Qta) >= ALL (
SELECT SUM(Qta)
FROM Vendita,Venditore
WHERE Vendita.CodVend = Venditore.Codice
AND Venditore.città= "verona"
GROUP BY Vendita.CodVend

17-01-2009 09:42
Click Here to See the Profile for morte2097 Click here to Send morte2097 a Private Message Find more posts by morte2097 Add morte2097 to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
morte2097
.primate.

User info:
Registered: Sep 2004
Posts: 68 (0.01 al dì)
Location: --------------------------------
Corso: info
Anno: primo
Time Online: 1 Day, 14:12:29 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

non ho kiuso la parentesi tonda della query interna!

17-01-2009 09:44
Click Here to See the Profile for morte2097 Click here to Send morte2097 a Private Message Find more posts by morte2097 Add morte2097 to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
R1cky`
dsy developer

User info:
Registered: Oct 2007
Posts: 218 (0.03 al dì)
Location:
Corso: Informatica Magistrale
Anno: Secondo
Time Online: 1 Day, 13:11:53 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Io l'ho fatta in questo modo: http://pastebin.com/m7d01f7d2

Last edited by R1cky` on 17-01-2009 at 13:11

17-01-2009 13:08
Click Here to See the Profile for R1cky` Click here to Send R1cky` a Private Message Find more posts by R1cky` Add R1cky` to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
morte2097
.primate.

User info:
Registered: Sep 2004
Posts: 68 (0.01 al dì)
Location: --------------------------------
Corso: info
Anno: primo
Time Online: 1 Day, 14:12:29 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

si va bene comunque, un pò più complessa da vedere ma va benissimo!

17-01-2009 13:52
Click Here to See the Profile for morte2097 Click here to Send morte2097 a Private Message Find more posts by morte2097 Add morte2097 to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
All times are GMT. The time now is 03:05.    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.048 seconds (86.54% PHP - 13.46% MySQL) con 26 query.