gpt4 book ai didi

php - 将表中的计数反射(reflect)到字段(MySQL)

转载 作者:行者123 更新时间:2023-11-29 14:37:54 24 4
gpt4 key购买 nike

liked_table
-----------
user_id | topic | liked
2 | 3 | 1
3 | 3 | 1
5 | 3 | -1


topics_table
------------
topic_id | likes
3 | count(liked field from liked_table where topic from liked_table is this row's topic_id)

我可以像在 Excel 中那样在 MySQL 中编写这样的公式吗?

最佳答案

您可以创建一个 View 并在 View 中包含计算列,而不是使用包含计算值的表。 (访问 View 中的数据在很大程度上与使用实际表执行相同操作相同)。

MySQL View Documentation

关于php - 将表中的计数反射(reflect)到字段(MySQL),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8627687/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com