一句group by可以解决这个查询吗解决思路

WBOY
Release: 2016-06-13 10:54:16
Original
741 people have browsed it

一句group by可以解决这个查询吗
字段 a b c
  1 2 3
  2 3 2
  2 1 5
  5 3 4
  3 5 3
  3 4 7
  4 3 6
查询出 
1、a或b字段 包括3的 
2、a和b的组合只选择一条c值最大的

最后想得到的就是,
  2 3 2
  5 3 4
  3 4 7
表述的不太好,希望能看懂的帮忙解答一下



------解决方案--------------------
可以是可以的……

SQL code
SELECT a, b, MAX( c ) AS cFROM (SELECT 1 a, 2 b, 3 cUNION ALL SELECT 2 , 3, 2UNION ALL SELECT 2 , 1, 5UNION ALL SELECT 5 , 3, 4UNION ALL SELECT 3 , 5, 3UNION ALL SELECT 3 , 4, 7UNION ALL SELECT 4 , 3, 6)tWHERE t.a =3OR t.b =3GROUP BY (IF( t.a 
                 
              
              
        
            
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template