免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2413 | 回复: 4
打印 上一主题 下一主题

一个SQL问题有兴趣的,可以看看。 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-05-30 10:03 |只看该作者 |倒序浏览
select user.id
user.name,
user.age,
count(select num from login where login.user_id=user.id) as user_count
from user
where user_count > 10




现在要求出 user_count > 10 的,你如何处理??user_count不能直接使用??

下面是我的方法。

select * from (
select user.id
user.name,
user.age,
count(select num from login where login.user_id=user.id) as user_count
from user
) as new_user

where new_user.user_count > 10



我的好多sql写法是来自PostgreSQL 我习惯了这种写法。。

[ 本帖最后由 netkiller 于 2008-5-30 10:09 编辑 ]

论坛徽章:
0
2 [报告]
发表于 2008-05-30 10:15 |只看该作者
这种还可以,如果要换的话就只能GROUP BY 呢。

论坛徽章:
0
3 [报告]
发表于 2008-05-30 12:03 |只看该作者
再问一个问题。

select product .user_id, count(product .id)  from product where count(product .id) > 10 group by product .user_id

目的是取出用户的产品和产品数量。看上面。好像不能运行。我让得PostgreSQL上面我做过类似,是没问题的。

论坛徽章:
0
4 [报告]
发表于 2008-06-04 15:07 |只看该作者
select product .user_id, count(product .id)  from product  group by product .user_id having count(product .id) > 10

论坛徽章:
0
5 [报告]
发表于 2008-06-04 15:26 |只看该作者

回复 #3 netkiller 的帖子

select product .user_id, count(product .id) as c from product where c > 10 group by product .user_id
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP