这个没必要吧,一个表就行了。你的另一个表只是做一个汇总而己,需要时再 sum 来汇总也行啊。如果非要两个表, 那就更新一个表同时,再更新另一个总表。可以用事务来实现。
类似下面这样的触发器: create trigger updateDate after insert on A for each row begin update B set `总和字段` = (select count(`数据`) from A where F_Month='七月'); end或者你也可以在程序中实现,一插入数据同时更新B表,不过触发器的效率会高。
日: select sum(data) from table where y='$y' and m='$m' and d='$d'月: select sum(data) from table where y='$y' and m='$m' 年: select sum(data) from table where y='$y'一个表就可以了
那就更新一个表同时,再更新另一个总表。可以用事务来实现。
create trigger updateDate
after insert on A
for each row
begin
update B
set `总和字段` = (select count(`数据`) from A where F_Month='七月');
end或者你也可以在程序中实现,一插入数据同时更新B表,不过触发器的效率会高。
select sum(data) from table where y='$y' and m='$m' and d='$d'月:
select sum(data) from table where y='$y' and m='$m'
年:
select sum(data) from table where y='$y'一个表就可以了
然后在根据你想要的数据,创建一个视图
CREATE
/*[ALGORITHM = {UNDEFINED | MERGE | TEMPTABLE}]
[DEFINER = { user | CURRENT_USER }]
[SQL SECURITY { DEFINER | INVOKER }]*/
VIEW `dbbase`.`viewname`
AS
(SELECT * FROM ...)