dqoeghe9452 2014-02-23 09:49
浏览 12
已采纳

从一个表动态获取行并从其他表获取值将其汇总并插入到目标表中

x table has columns(Agency,datac)
Y table has columns(Agencyname,total)
EXAMPLE

Agency | datac
NET    | 100 
GOO    | 300 
NET    | 100 
GOO    | 100 

Agencyname | total
NET        |  
GOO        | 

first customer adds Agencyname then it gets update on table Y
From a dropdown menu in html i have made user to either choose NET OR GOO but what i want is how many values they may enter in table X.
i want their total sum to be inserted into table Y. so that my expected output looks like this

Agencyname | total
NET        | 200
GOO        | 400
  • 写回答

3条回答 默认 最新

  • dongtui0650 2014-02-23 09:59
    关注

    The most straight forward way is probably an update with a subquery;

    UPDATE TableY
    SET total = (SELECT SUM(datac) FROM TableX WHERE Agency=AgencyName)
    

    An SQLfiddle to test with.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 phython如何实现以下功能?查找同一用户名的消费金额合并—
  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿速度
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址