GROUP BY 语句可以实现某一列的去重查询。

直接上语句:
select io_dev_id from io_info where (TID=1 AND host_name='yang1') GROUP BY 1;
按照io_dev_id去重查询。
 
p:顺手加上与ORDER BY 和 distinct的区分使用
GROUP BY 是根据列捡选
ORDER BY 是根据列排序
distinct类似于 GROUP BY ,但是只能放在 select 后面,被筛选的字段前面。
如:select distinct a,b,c from tb1;
选出的是a、b、c三列值都相同的数据。
 
摘取的mysql 5.6 reference manual中的内容:
In most cases, a DISTINCT clause can be considered as a special case of GROUP BY. For example, the following two queries are equivalent:
 
SELECT DISTINCT c1, c2, c3 FROM t1
WHERE c1 > const;
SELECT c1, c2, c3 FROM t1
WHERE c1 > const GROUP BY c1, c2, c3;

相关文章:

  • 2021-12-18
  • 2022-12-23
  • 2022-12-23
  • 2022-03-05
  • 2021-11-18
  • 2021-12-01
  • 2021-12-14
  • 2021-05-30
猜你喜欢
  • 2021-06-20
  • 2021-08-19
  • 2021-06-19
  • 2021-11-30
  • 2022-01-07
  • 2021-09-13
  • 2021-07-09
相关资源
相似解决方案