我需要將所有Start_Stop_ID和End_Stop_ID組合到一個ID列中,但我需要將每個Stop_ID的開始和結束數計入單獨的列中。MySQL選擇查詢:計算計數並獲得總計
Start_Stop_ID的每一行都有Current_Fare。我需要計算與Start_Stop_ID關聯的Current_Fare的總數,而不是End_Stop_ID。
The columns would be: ID | Start | END | TOTAL Example: There would be rows such as E1 | 1 | 0 | 3.50 BUSDOME | 3 | 0 | 18.50 (BUSDOME has 3 Start_Stop_ID, 10.50, 4.00 and 4.00) N4 | 1 | 3 | 1.50 E5 | 2 | 0 | 6.00 (E5 has 2 Start_Stop_ID, 3.00 and 3.00) E7 | 0 | 1 | 0.00
旅行表
我想的第一列是在Start_Stop_ID每個ID和在End_Stop_ID每個ID的第二計數的計數。因此,N4在Start_Stop_ID中出現一次,在End_Stop_ID中出現3次。然後,:N4 | 1 | 3 | 1.50 看起來總數僅僅基於Current_Fare中的ID列出現在第一列中。 – Arcesilas
我想計算End_Stop_ID的總數並將其放入列中,但它與Start_Stop_ID的計數位於同一行。 –
正如@Arcesilas所說,Current_Fare的總和只是基於Start_Stop_ID –