Visualizzazione dei risultati da 1 a 8 su 8

Discussione: Query Somma in MySQL

  1. #1
    Utente di HTML.it L'avatar di wegawhite
    Registrato dal
    Aug 2004
    Messaggi
    1,400

    Query Somma in MySQL

    Ciao, mi spiegate dove sbaglio con queste query?:

    codice:
    Set RS = Server.CreateObject("ADODB.Recordset")
    sql = " select VisitProven from tbl_sessioni "
    sql = sql & " where VisitProven <> '' "
    RS.Open sql, objConn, 3, 3
    
    x = 0
    Do While NOT RS.EOF
    
    x = x + 1
    
    response.write x &"-"&  RS("VisitProven") &"
    "
    
    sSQL = "SELECT VISITPROVEN, SUM(VISITORCOUNT) AS VISITORCOUNT from FROM tbl_SESSIONI WHERE VISITPROVEN = "& RS("VisitProven") &"  GROUP BY VISITPROVEN "
    set oRS = objconn.execute(sSQL) <<< riga errore
    
    RS.MoveNext
    Loop
    
    
    oRS.Close
    set oRS = Nothing
    
    rs.Close
    set rs = Nothing
    
    objConn.Close
    set objConn = Nothing
    Errore:
    Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

    [MySQL][ODBC 3.51 Driver][mysqld-5.0.21-community-nt]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM tbl_SESSIONI WHERE VISITPROVEN = ITALY' GROUP BY VISITPROVEN' at line 1

  2. #2
    italy me pare 'na stringa. apiciala

  3. #3
    Utente di HTML.it L'avatar di wegawhite
    Registrato dal
    Aug 2004
    Messaggi
    1,400
    Originariamente inviato da optime
    italy me pare 'na stringa. apiciala
    sSQL = "SELECT VISITPROVEN, SUM(VISITORCOUNT) AS VISITORCOUNT FROM tbl_SESSIONI WHERE VISITPROVEN = '"& RS("VisitProven") &"' GROUP BY VISITPROVEN "
    Mi dà lo stesso errore... nel db mysql VISITPROVEN è varchar(50) :master:

  4. #4

  5. #5
    Utente di HTML.it L'avatar di wegawhite
    Registrato dal
    Aug 2004
    Messaggi
    1,400
    Originariamente inviato da optime
    fatti ristampare la sql
    Si infatti c'era un apice in più...

    Ho un altro problema: eseguita questa query SUM come faccio a prendere SOLTANTO i tre valori più alti ed inserirli in una seconda tabella?

  6. #6

  7. #7
    Utente di HTML.it L'avatar di wegawhite
    Registrato dal
    Aug 2004
    Messaggi
    1,400
    limit in questa query?:

    codice:
    sSQL = "SELECT "
    sSQL = sSQL & " VISITPROVEN, "
    sSQL = sSQL & " SUM(VISITORCOUNT) "
    sSQL = sSQL & " AS VISITORCOUNT "
    sSQL = sSQL & " FROM tbl_SESSIONI "
    sSQL = sSQL & " WHERE VISITPROVEN = '"&  RS("VisitProven") &"' "
    sSQL = sSQL & " GROUP BY VISITPROVEN "
    set oRS = objconn.execute(sSQL)
    nun capisco...

  8. #8
    Utente di HTML.it L'avatar di wegawhite
    Registrato dal
    Aug 2004
    Messaggi
    1,400
    Ho fatto così:

    codice:
    Set RS = Server.CreateObject("ADODB.Recordset")
    sql = " select VisitProven from tbl_sessioni "
    sql = sql & " where VisitProven <> '' "
    RS.Open sql, objConn, 3, 3
    
    Do While NOT RS.EOF
    
    sSQL = "SELECT "
    sSQL = sSQL & " VISITPROVEN, "
    sSQL = sSQL & " SUM(VISITORCOUNT) "
    sSQL = sSQL & " AS VISITORCOUNT "
    sSQL = sSQL & " FROM tbl_SESSIONI "
    sSQL = sSQL & " WHERE VISITPROVEN = '"&  RS("VisitProven") &"' "
    sSQL = sSQL & " GROUP BY VISITPROVEN"
    set oRS = objconn.execute(sSQL)
    
    strSQL = "INSERT INTO tbl_stat" 
    strSQL = strSQL & " (" 
    strSQL = strSQL & "VisitProven," 
    strSQL = strSQL & "VisitorCount)" 
    strSQL = strSQL & " VALUES " 
    strSQL = strSQL & "(" 
    strSQL = strSQL & "'"& RS("VisitProven") &"'," 
    strSQL = strSQL & ""& oRS("VISITORCOUNT") &"" 
    strSQL = strSQL & ")  "
    set objRS = objconn.execute(strSQL)
    
    RS.MoveNext
    Loop
    Ma per ogni records della query select sSQL mi inserisce un record nella tbl_stat che contiene il totale di VisitProven...

    Dove sbaglio?

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.