doupaoshu8334 2015-11-19 09:40
浏览 31
已采纳

MySQL Sum-up值并将它们插入表中

I have this Database:

Table Name: Single Database: Produkt
ID  PID     BID            ListingID    Brand   PN     Model
1   1234    XXXXXXXX    1234-XXXXXXXX   Nike    P14    505
1   1234    XXXXXXXX    1234-XXXXXXXX   Nike    P14    715
1   1234    XXXXXXXX    1234-XXXXXXXX   Puma    P14    L14
1   1234    XXXXXXXX    1234-XXXXXXXX   Puma    P14    P15
2   1234    XXXXXXXX    1234-XXXXXXXX   Samsung XL14XL 505
2   1234    XXXXXXXX    1234-XXXXXXXX   Samsung XL14XL 715
2   1234    XXXXXXXX    1234-XXXXXXXX   Samsung XL14XL L14
2   1234    XXXXXXXX    1234-XXXXXXXX   Samsung XL14XL P14
3   1234    XXXXXXXX    1234-XXXXXXXX   EPSON   P14    503
3   1234    XXXXXXXX    1234-XXXXXXXX   EPSON   P14    503
3   1234    XXXXXXXX    1234-XXXXXXXX   EPSON   P14    703
3   1234    XXXXXXXX    1234-XXXXXXXX   EPSON   P14    713
4   1234    XXXXXXXX    1234-XXXXXXXX   EPSON   P14    715
4   1234    XXXXXXXX    1234-XXXXXXXX   EPSON   P14    503

And i want to sum up the "Model" in the lines Where "ID-Brand-PN" is the same

This is how i want my new Table to look:

Table Name: master Database: Produkt
ID  Brand   PN      AModel
1   Nike    P14     505, 715
1   Puma    P14     L14, P15
2   Samsung XL14XL  505, 715, L14, P14
3   EPSON   P14     503, 703, 713
4   EPSON   P14     715, 503



Pseudo-Code:
Single Row = 1

for each Single Row= NOT NULL{
IF Single Row ID and Brand and PN and Model = Exist
{
Insert into AModel Row where it exists ", Model"  
}
ELSE 
{
Write Single ID and Brand and PN and Model into Master
Single Row + 1}

Thanks for your time and effort, if you need more Details i´ll provide them, I don´t mind writing a php Script when i can make a trigger that which starts the Script when a new row is added to single

  • 写回答

1条回答 默认 最新

  • 普通网友 2015-11-19 09:44
    关注

    Here is the MySQL query which will generate the output table you want:

    SELECT ID, Brand, PN, GROUP_CONCAT(Model)
    FROM Single
    GROUP BY ID, Brand, PN
    

    Since you don't mind writing the PHP script, I'll leave that to you :-)

    SQLFiddle

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c