新人求教SQL插入数据提问

我在做一个新闻相关的网页,其中有一个添加新闻的功能,添加新闻表中,新闻表有type字段表示新闻的类型,然后新闻类别表中有amount字段表示类型的数量,请问怎么实现amount中可以统计type的数量啊?

select sum(type) from 新闻表 group by type

每次新添加新闻类型的时候都去在amount上增加相同数量

select * from(select count(1) from 新闻表 group by type)where type=新闻类型,oracle的话用子查询

select count(distinct(type)) from 新闻表

通过这个语句来统计各个类型的数量select * from (select count(1) from 新闻表 group by t.type)t where t.type in (select distinct type from 新闻表 )order by t.type;

上面的修改一下 :select count ( * ) from (select * from 新闻表 group by t.type)t where t.type in (select distinct type from 新闻表 )order by t.type;

sorry ,上面两个都错了,改为select * from (select count( * ) ,type from 新闻表 t group by t.type) t1 where t1.type in (select distinct type from 新闻表) order by t1.type ; 查询出每个类型的总数量,再到类别表里面进行更更新amount的数量即可。

代码控制,每次insert新闻表,update新闻类型表对应类型的数量+1;