Visualizzazione dei risultati da 1 a 5 su 5

Discussione: select count

  1. #1
    Utente di HTML.it
    Registrato dal
    May 2003
    Messaggi
    269

    select count

    ho una tabella (dati) che ha 32 campi ( d1...d32) ognuno di questi campi può avere un valore che sia A,B,C,o D .

    come faccio a scrivere (correttamente ) una query che conti il numero dei record A , quanti B ...quanti D ecc..

    la mia stringa (che non funziona è )
    codice:
    <%
    
    CNN=Application("CNN")
    
    	set conn=Server.CreateObject("ADODB.Connection")
    	conn.open CNN 
    	set rs=server.createobject("ADODB.recordset")
    
    qry10="SELECT count(*) as id FROM dati WHERE (d1 = '"&("A")&"' and d2= '"&("A")&"' ...and d32= '"&("A")&"') ;"
    rs.Open qry10,conn
    conn.execute(qry10)
    response.write " 
    "& rs.fields("id") & ""
    rs.close
    %>

  2. #2
    Utente di HTML.it L'avatar di Sypher
    Registrato dal
    Jun 2003
    Messaggi
    1,994
    per come hai scritto tu...mettendoli in and ti restituirebbe solo il count dei record che hanno tutti quei campi da d1 a d32 valorizzati con A...quindi intanto usa or...ma non credo che basti...sto pensando o forse si...fai qualche prova
    La passera non dura perchè Sypher la cattura!

    "No one like us we don't care, we are millwall, super millwall, we are millwall from the DEN"

  3. #3
    Utente di HTML.it
    Registrato dal
    May 2003
    Messaggi
    269
    grazie ma non va nè con or nè con and , purtroppo la tabella è nata male ;-)

    ma non posso modificarla ....

  4. #4
    Moderatore di JavaScript L'avatar di br1
    Registrato dal
    Jul 1999
    Messaggi
    19,998
    select codice, sum(quanti) as id
    from (
    select d1 as codice, count(*) as quanti from dati group by d1
    union
    select d2 as codice, count(*) as quanti from dati group by d2
    union
    ... ... ...
    select d31 as codice, count(*) as quanti from dati group by d31
    )
    group by codice;


    ma forse non ho capito...

    ciao
    Il guaio per i poveri computers e' che sono gli uomini a comandarli.

    Attenzione ai titoli delle discussioni: (ri)leggete il regolamento
    Consultate la discussione in rilievo: script / discussioni utili
    Usate la funzione di Ricerca del Forum

  5. #5
    Utente di HTML.it
    Registrato dal
    May 2003
    Messaggi
    269
    trovato ,un pò lungo ma funge
    codice:
    dim tot1 
    tot1 = 0
    dim tot2 
    tot2 = 0
    dim tot3 
    tot3 = 0
    dim tot4
    tot4 = 0
    CNN=Application("CNN")
    
    	set conn=Server.CreateObject("ADODB.Connection")
    	conn.open CNN 
    	set rs=server.createobject("ADODB.recordset")
    ' select domanda 1(d1)	
    qry1="SELECT DISTINCT (d1) AS Espr1, Count(*) AS Espr2 FROM dati GROUP BY dati.d1"
    rs.Open qry1,conn
    
    if rs.eof then
    response.write ("no dati")
    
    else
    
    'conn.execute(qry1)
    while not rs.EOF
    'response.write espr1
    if rs.fields("espr1") = "sono assolutamente d accordo" then
    
    tot1 = tot1 + rs.fields("espr2")
    end if 
    if rs.fields("espr1") = "sono abbastanza d accordo" then
    
    tot2 = tot2 + rs.fields("espr2")
    end if 
    if rs.fields("espr1") = "non sono del tutto d accordo" then
    
    tot3 = tot3 + rs.fields("espr2")
    end if 
    if rs.fields("espr1") = "non sono affatto d accordo" then
    
    tot4 = tot4 + rs.fields("espr2")
    end if 
    'response.write " 
    "& rs.fields("espr1") & ""
    'response.write " 
    "& rs.fields("espr2") & ""
    
    
    rs.MoveNext
    	wend
    end if
    
    rs.close
    
    ...ripeti per tutte le 32 domande...
    
    <font color="#0000FF" face="Verdana, Arial, Helvetica, sans-serif">Totali per risposta </font>
    
      <%
    'scrittura dei dati 
    response.write "sono assolutamente d accordo : "& tot1 & "
    "
    response.write "sono abbastanza d accordo : "& tot2 & "
    "
    response.write "non sono del tutto d accordo : "& tot3 & "
    "
    response.write "non sono affatto d accordo : "& tot4 & "
    "
    
    set rs=nothing
    
    conn.close
    set conn=nothing
    
    
    %>
      <% 
    
    Dim Valori1
    Dim Valori2
    Dim Valori3
    Dim Valori4
    Dim Categorie(4)
    Set cs = Server.CreateObject("OWC10.ChartSpace")
    Set chConstants = cs.Constants
    Set chart = cs.charts.add
    'chart.type = chConstants.chChartTypeRadarLineFilled
    chart.type = 47
    
    set serie1 = chart.seriesCollection.add 
    set serie2 = chart.seriesCollection.add 
    set serie3 = chart.seriesCollection.add 
    set serie4 = chart.seriesCollection.add 
    
    categorie(1) = "sono assolutamente d accordo"
    categorie(2) = "sono abbastanza d accordo"
    categorie(3) = "non sono del tutto d accordo"
    categorie(4) = "non sono affatto d accordo"
    
    valori1 =  tot1 
    valori2 =  tot2
    valori3 =  tot3
    valori4 =  tot4
    
    serie1.SetData chConstants.chDimCategories, chConstants.chDataLiteral, categorie(1)
    serie1.SetData chConstants.chDimValues, chConstants.chDataLiteral, valori1
    
    serie2.SetData chConstants.chDimCategories, chConstants.chDataLiteral, categorie(2)
    serie2.SetData chConstants.chDimValues, chConstants.chDataLiteral, valori2
    
    serie3.SetData chConstants.chDimCategories, chConstants.chDataLiteral, categorie(3)
    serie3.SetData chConstants.chDimValues, chConstants.chDataLiteral, valori3
    
    serie4.SetData chConstants.chDimCategories, chConstants.chDataLiteral, categorie(4)
    serie4.SetData chConstants.chDimValues, chConstants.chDataLiteral, valori4
    
    cs.ExportPicture server.MapPath("images/prova1.gif"), "GIF", 400, 400
    Set cs = Nothing
    
    %>
      [img]images/prova1.gif[/img]
    e alla fine ti produci anche il grafico

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.