• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

关于mysql触发器或SP的有关问题

mysql 搞代码 7年前 (2018-05-31) 198次浏览 已收录 0个评论

关于mysql触发器或SP的问题
原始数据表:
branch_id|flow_total|flow_free|flow_nofree|effect_time
  1 | 256 | 128 | 128 | 2010-09-10 00:00:00
  1 | 1024 | 256 | 768 | 2010-09-10 00:05:00
  2 | 1024 | 256 | 768 | 2010-09-10 00:00:00
  2 | 1024 | 256 | 768 | 2010-09-10 00:05:00
日表
branch_id|flow_total|flow_free|flow_nofree|effect_time
  1 | 1280 | 384 | 896 | 2010-09-10
  2 | 2048 | 512 | 1536 | 2010-09-10
周表
branch_id|flow_total|flow_free|flow_nofree|effect_time
  1 | 1280 | 384 | 896 | 周日期
  2 | 2048 | 512 | 1536 | 周日期

月表
branch_id|flow_total|flow_free|flow_nofree|effect_time
  1 | 1280 | 384 | 896 | 2010-09-10
  2 | 2048 | 512 | 1536 | 2010-09-10
年表
branch_id|flow_total|flow_free|flow_nofree|effect_time
  1 | 1280 | 384 | 896 | 2010
  2 | 2048 | 512 | 1536 | 2010

现在这个sp或者触发器应该怎么做呢?
请高手能给出具体代码

——解决方案——————–

SQL code

 create TABLE t10( branch_id INT(11), flow_total INT(11), flow_free INT(11), flow_nofree INT(11) , effect_time datetime); insert into t10 values (1,256,128,128,'2010-09-10 00:00:00'), (1,1024,256,768,'2010-09-10 00:05:00'), (2,1024,256,768,'2010-09-10 00:00:00'), (2,1024,256,768,'2010-09-10 00:05:00'); select * from t10; # 日 select branch_id,sum(flow_total),sum(flow_free),sum(flow_nofree),date_format(effect_time,'%Y-%m-%d') from t10 group by branch_id,date_format(effect_time,'%Y-%m-%d'); # 周 select branch_id,sum(flow_total),sum(flow_free),sum(flow_nofree),yearweek(effect_time) from t10 group by branch_id,yearweek(effect_time); # 月 select branch_id,sum(flow_total),sum(flow_free),sum(flow_nofree),date_format(effect_time,'%Y-%m') from t10 group by branch_id,date_format(effect_time,'%Y-%m'); # 年 select branch_id,sum(flow_total),sum(flow_free),sum(flow_nofree),date_format(effect_time,'%Y') from t10 group by branch_id,date_format(effect_time,'%Y');

欢迎大家阅读《关于mysql触发器或SP的有关问题》,跪求各位点评,by 搞代码


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:关于mysql触发器或SP的有关问题
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址