select a,sum(b) as totalQty
from tblName where idz=10
group by idz,a
注意idz如果不是数字则筛选10要对其加单引号
(我把你表格中的数据 "中文" 换成了 "英文" 数据和你的是一致的)我创建你的表格的SQL语句:create table cellphone( id int(3) zerofill not null auto_increment primary key, title char(20) not null, number int not null, type char(20) not null, time date not null)插入数据的SQL语句:insert into cellphone (title,number,type,time) values("Phone Model 1",90,"cellphone","2012-08-14"),("Phone Model 1",90,"cellphone","2012-08-14"),("Phone Model 2",100,"cellphone","2012-08-14"),("Mobile Accessory 1",100,"Accessory","2012-08-14")查询语句:select title, sum(number), time from cellphonewhere type = 'cellphone'and time= date_format(now(),'%Y-%m-%d') //获取今天日期的函数group by title创建后的表:查询结果:php 实现代码:运行结果:欢迎分享,转载请注明来源:内存溢出
评论列表(0条)