2011-12-25 20 views
0
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中編寫這樣的公式嗎?將表中的數字反映到字段中(MySQL)

回答

1

您可以創建視圖並在視圖中計算出列,而不是使用包含計算值的表格。 (在視圖中訪問數據與在實際表中執行相同的操作大部分是相同的)。

MySQL View Documentation

相關問題