MySQL How do I create this subquery?

后端 未结 2 1031
情话喂你
情话喂你 2021-01-05 00:40

I have the following tables

Table Farm

+---------+--------+-------------------+-----------+------------+
| FARM_ID |Stock_ID| FARM_T         


        
2条回答
  •  囚心锁ツ
    2021-01-05 01:26

    I would take your original query to get the second last table and change the Select by adding use distinct (found here) and only select Origin, Stock and the calculation for the Score. For example if the score is an average of all of them it would be AVG(Score) where Score would be what you fetched in the original query. If you want to use only a small subset of the items that have the same Origin and Stock to calculate the Score I would use a subquery, with the where matching the Origin and Stick ids, in the select so you have:

    Select Origin, 
           Stock, 
           (select calculation(Score) from tables where tables.stock_id = .... tables.origin_id = .....)
    From....
    

    Hope this helps.

提交回复
热议问题