求SQL语句

处处留心 2015-07-22 05:57:32
举个例子:
表名: person
字段: Name sex age(整数,例如:1,2,3,4) CardNo
现在我想检索出,性别是女的,某个年龄段人数大于1的所有人的信息集合

举个例子,如果表中,28岁女性数目有二个人以上,就取出年龄在28岁的所有女性的信息
select t.CardNo count(t.CardNo), t.Name, t.age ,t.sex from person t where t.sex = '女' and count(t.CardNo) > 1 Group by t.Age , t.CardNo

这个SQL语句是错的。但是我想要表达的意思



求指教
...全文
485 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
zy18755122285 2016-03-08
  • 打赏
  • 举报
回复
惑先生 2015-09-06
  • 打赏
  • 举报
回复
select * from ( select t.CardNo count(t.CardNo) over(partition by t.age) as cnt, t.Name, t.age ,t.sex from person t where t.sex = '女' ) where cnt > 1
越烟 2015-09-04
  • 打赏
  • 举报
回复
select * from ( select p.*, count(1) over(partition by age) cnt from person where sex='女' ) where cnt>=2 楼主这个查询可以满足你的要求, 速度最快。 这个是oracle 分析函数, 我看其他人也没有写......
塑料勺 2015-07-24
  • 打赏
  • 举报
回复
select * from person t where (select count(*) from person s where sex = '女' and age = 28) >= 2 and sex = '女' and age = 28
印度张三 2015-07-23
  • 打赏
  • 举报
回复
 select * from person where name in (
 select Name from   person where sex ='女' and  age=28 
 )
 
Tiger_Zhao 2015-07-23
  • 打赏
  • 举报
回复
    SELECT t.*
      FROM ( -- 先统计出一人以上的年龄段
                SELECT age
                  FROM person
                 WHERE sex = '女'
              GROUP BY age
                HAVING COUNT(*) > 1
           ) s
      JOIN person t
        ON s.age = t.age -- 再用年龄段过滤明细
     WHERE t.sex = '女'
  ORDER BY t.Age , t.CardNo
mayanzs 2015-07-23
  • 打赏
  • 举报
回复

with ag as (select t.age,count(t.CardNo) as count_n from person t where t.sex='女' group by t.age having count(t.CardNo)>1)
select * from person u where u.sex='女' and exists (select 1 from ag where ag.age=u.age);
mayanzs 2015-07-23
  • 打赏
  • 举报
回复

 select   t.CardNo,  t.Name,  t.age ,t.sex ,count(t.CardNo) as count_num from person  t
   where   t.sex = '女' 
   Group   by   t.CardNo,  t.Name,  t.age ,t.sex
   having count(t.CardNo) > 1
碧水幽幽泉 2015-07-22
  • 打赏
  • 举报
回复
某个年龄段人数大于1的所有人的信息集合,麻烦详细解释下。

3,490

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 高级技术相关讨论专区
社区管理员
  • 高级技术社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧