SQL如何计算数据库中同一行的出现数量
我的数据在mySQL表中:
Cart_id Product_id Quantity
1 1 1
我可以以某种方式做到这一点:当我添加datas的下一个行时: cart_id 1和product_id 1和数量1,新行将不会插入,但是第一行将更新为2的数量?
但是,当我插入数据:cart_id 1和product_id 2时,将插入新行。
My data in mySql table:
Cart_id Product_id Quantity
1 1 1
Can i do somehow, that acction: when i add next row with datas:
cart_id 1 and product_id 1 and quantity 1 , the new row will be not inserted, but the first row will update quantity to 2?
But when i insert datas: cart_id 1 and product_id 2, the new row will be inserted.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用这样的查询:
在这里示例:
创建一个表:
添加唯一索引:
您还可以在创建创建索引时指导创建索引表
插入行样本:
Use a Query like this:
Here a Sample:
create a Table:
add the unique index:
you can also direct create the index when creating the table
insert rows sample: