MySQL:从子查询结果更新表列
会员表上有“MemberID”和“PointsEarned”列。
我想根据此查询的结果更新 PointsEarned 列:
SELECT m.MemberID, m.UserName,
( (SELECT COUNT(*) FROM EventsLog as e WHERE e.MemberID=m.MemberID AND e.EventsTypeID=2)*10 ) +
( (SELECT COUNT(*) FROM EventsLog as e WHERE e.MemberID=m.MemberID AND e.EventsTypeID=3)*3 ) +
( (SELECT COUNT(*) FROM ChatMessages as c WHERE c.MemberID=m.MemberID)*.1 )
as PointsEarned
FROM Members as m
任何人都可以告诉我应该如何使用单个查询来完成此操作?
谢谢!
On the Members table are columns "MemberID" and "PointsEarned".
I want to update the PointsEarned column from the result of this query:
SELECT m.MemberID, m.UserName,
( (SELECT COUNT(*) FROM EventsLog as e WHERE e.MemberID=m.MemberID AND e.EventsTypeID=2)*10 ) +
( (SELECT COUNT(*) FROM EventsLog as e WHERE e.MemberID=m.MemberID AND e.EventsTypeID=3)*3 ) +
( (SELECT COUNT(*) FROM ChatMessages as c WHERE c.MemberID=m.MemberID)*.1 )
as PointsEarned
FROM Members as m
Can anybody tell me how I should do it with a single query?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能想尝试以下操作:
测试用例:
结果:
You may want to try the following:
Test case:
Result: