mysql将X列的行列值与同一个表中的另一列匹配

时间:2016-08-04 15:29:52

标签: php mysql

嗨,这并不意味着粗鲁,但我是mysql的新手

表:信息
列:id,squad_1,squad_2,squad_12_result,squad_3,squad_4,squad_34_result

id  squad_1 squad_2 squad_12_result squad_3 squad_4 squad_34_result
--- ------- ------- --------------- ------- ------- ---------------
10     a       b          win          g        l          win
9      a       c          win          g        m          lose
8      a       d          draw         g        n          win
7      a       e          lose         g        o          win
6      a       f          win          g        p          draw
5      a       g          win          g        q          lose
4      a       h          win          g        r          win
3      a       i          draw         g        s          win
2      a       j          lose         g        t          lose
1      a       k          win          g        u          draw

我想要实现的是最近5行'squad_12_result'列匹配'squad_34_result'的整行

表示输出结果类似于

id  squad_1 squad_2 squad_12_result | id  squad_3 squad_4 squad_34_result
--- ------- ------- --------------- | --- ------- ------- ---------------
10     a       b          win       | 8     g        n          win
9      a       c          win       | 7     g        o          win
8      a       d          draw      | 6     g        p          draw
7      a       e          lose      | 5     g        q          lose
6      a       f          win       | 4     g        r          win

有没有办法实现它?欢迎任何建议

我似乎能够通过运行此查询来匹配两列的结果

        SELECT * 
        FROM `info` 
        WHERE squad_12_result
        LIKE squad_34_result

只返回

id  squad_1 squad_2 squad_12_result squad_3 squad_4 squad_34_result
--- ------- ------- --------------- ------- ------- ---------------
10     a       b          win          g        l          win
4      a       h          win          g        r          win
2      a       j          lose         g        t          lose

是否有任何工作要匹配“squad_12_result”

id  squad_1 squad_2 squad_12_result
--- ------- ------- ---------------
10     a       b          win         
9      a       c          win         
8      a       d          draw        
7      a       e          lose      
6      a       f          win        

用“squad_34_result”?

id  squad_3 squad_4 squad_34_result
--- ------- ------- ---------------
8     g        n          win
7     g        o          win
6     g        p          draw
5     g        q          lose
4     g        r          win    

基本上它将“squad_12_result”的最新“5”行与“squad_34_result”的整行进行比较,因为您可以看到它与结果列匹配

理想输出将是这样的

id  squad_1 squad_2 squad_12_result | id  squad_3 squad_4 squad_34_result
--- ------- ------- --------------- | --- ------- ------- ---------------
10     a       b          win       | 8     g        n          win
9      a       c          win       | 7     g        o          win
8      a       d          draw      | 6     g        p          draw
7      a       e          lose      | 5     g        q          lose
6      a       f          win       | 4     g        r          win

0 个答案:

没有答案