group by后提取数据有关问题

group by后提取数据问题
group by后提取数据有关问题


如图,请问我怎么在存储过程中把这些值对应的插入另外一张表
------解决方案--------------------
你可以不用存储过程,例如

insert into table(cnt,unit_id)
select count(*),unit_id from your_table
group by unit_id

------解决方案--------------------
insert into tb (cnt,unit_id)
select count(*)cnt,unit_id from your_tb
group by unit_id;
------解决方案--------------------
貌似触发器在定义的时候只定义了delete、insert 和update的操作的触发器,没有定义在查询时候能触发触发器。所以在分组统计查询的时候可能不能实现用触发器执行插入操作,顾你可以换另一种方式去解决这个问题。
就像上面提供的思路:在进行分组统计的时候就进行插入操作,
insert into t_count_reslut(cnt,unit_id)
select count(*),unit_id from t_select
group by unit_id;