[英]Query for Summing the values based on text mysql
基本上我有這張桌子。 我需要基於crop_text的crop_stage值的總和
---------- ----------
crop_stage crop_text
---------- ----------
12 Preflowering
3 Fertilizing
10 Sowing
10 Sowing
2 Preflowering
15 Fertilizing
我需要更新crop_stage的值,這樣我就可以
---------- ----------
crop_stage crop_text
---------- ----------
14 Preflowering
18 Fertilizing
20 Sowing
我寫了我的選擇查詢,它不能很好地工作。
"SELECT crop_text, SUM(crop_stage) AS crop_stage FROM table GROUP BY crop_text"
編輯
我正在用我的選擇查詢做json_encode,這實際上是給我的。
[["Preflowering",12],["Fertilizing",3],["Sowing",10],["Sowing",10],["Preflowering",2],["Fertilizing",15]
字table
是保留的。 像這樣編寫查詢:
SELECT crop_text, SUM(crop_stage) AS crop_stage FROM `table` GROUP BY crop_text;
希望這可以幫助
選擇crop_text,SUM(crop_stage)AScrop_stage FROM table_name GROUP BYcrop_text順序按crop_stage ASC
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.