一,今天给大家讲一下,做留言的一种追加的方式主要如果当前有留言,就更新当前的留言以追加的方式,如果没能留言就将入一条新的
mysql:insert into `table` (field) values ('$value') on duplicate key update `field`=concat('value',ifnull(`field`,''));
具体本条SQL的用法,请查看手册
二,讲一下统计的用法,主要介绍如何用一条SQL语句,统计某个用户的某个字段中不同状态的合
首先,(select t.username,t.action,count(*) as num from t group by t.username,t.action) as N用分组的方式将不同的用户中的某个字段的某些状态分组求合这是子句
然后,select N.username,max(CASE N.action where 'field1' then n.num else 0 end) as field1_num,max(CASE N.action where 'field2' then n.num else 0 end) as field2_num from ,(select t.username,t.action,count(*) as num from t group by t.username,t.action) as N group by N.username
然后分别显示username,field1_num,field2_num