mysql 子表查询;去重查询

xiaoxiao2021-02-28  77

假设 表名:tb1

        列:id,name,age

1. 子表查询:

    (1)得到年龄大于16的结果:

select * from tb1 where age>16;

      (2) 在上述的基础上,得到id<100的结果:            

select * from ( select * from tb1 where age>16) as tmp;        注意后面的 as tmp一定要加上,不然会提示错误:缺少alias.

2. 假设我们的tb1中有一部分数据是完全重复的,那么我们可以使用下面的语句得到不重复的结果:

select distinct(*) from tb1;如果想统计非重复的结果一共有多少条,可以使用:

select count(*) from (select distinct(*) from tb1);

转载请注明原文地址: https://www.6miu.com/read-76567.html

最新回复(0)