我需要将所有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 –