Soma De Dados Repetidos
Started By Osnel, 23/06/2005, 14:22
5 replies to this topic
#1
Posted 23/06/2005, 14:22
Tenho uma tabela no qual a vários dados repetidos, preciso somar os dados que neles se repetem...
laranja
Laranja
tomate
tomate
tomate
abobora
lista laranja 2
Tomate 3
Abobora 1
como faço ?
laranja
Laranja
tomate
tomate
tomate
abobora
lista laranja 2
Tomate 3
Abobora 1
como faço ?
#2
Posted 23/06/2005, 14:57
Se entendi direito, acho q eh isso:
Pra exibir o total:
Sql = "SELECT COUNT(CAMPO) AS TOTAL FROM TABELA WHERE CAMPO2 = 'Tomate'" Set Rs = Conn.Execute(Sql)
Pra exibir o total:
Response.write(Rs("TOTAL"))
Eduardo Batista
#3
Posted 23/06/2005, 15:14
+/- isso...
so que eu preciso listar assim
3 tomate
2 laranjas
1 abobora
Valew cara
so que eu preciso listar assim
3 tomate
2 laranjas
1 abobora
Valew cara
#4
Posted 23/06/2005, 15:51
Sql = "SELECT COUNT(CAMPO) AS TOTAL,CAMPO FROM TABELA WHERE CAMPO = CAMPO GROUP BY CAMPO" Set Rs = Conn.Execute(Sql) If Not Rs.Eof or Not Rs.Bof Then Do While Not Rs.Eof Response.Write(Rs("TOTAL") & " - " & Rs("CAMPO") & "<br>") Rs.Movenext Loop End If
Abs.
Eduardo Batista
#5
Posted 23/06/2005, 16:35
No MySQL pode fazer assim:
SELECT campo, COUNT(*) total FROM tabela GROUP BY campo
#6
Posted 23/06/2005, 18:53
usando msSQL
para exibir fica assim
<%
set rs = Server.CreateObject("ADODB.Recordset")
sqlstr="select laranjas from TABELA where produto=laranja"
rs.open sqlstr,conn,1,1
tatalrecord=rs.recordcount
total1=tatalrecord
rs.close
%>
para exibir fica assim
para os outros produtos é so repetir o esquema<%=total1%> laranjas.
Edição feita por: luizj, 23/06/2005, 18:54.
Compare preços online no Melhor Comprar
1 user(s) are reading this topic
0 membro(s), 1 visitante(s) e 0 membros anônimo(s)