sql语句问题,distinct和top如何共存?

jerryf 2005-04-14 09:36:46
我有一张表有一些名称相同的记录,我用distinct取:
select distinct g_name,g_image_m,g_price from goods where g_isnew='y',
取出来的记录有很多,但是我只要显示前6条:
select top 6 distinct g_name,g_image_m,g_price from goods where g_isnew='y'
有错:
Microsoft JET Database Engine 错误 '80040e14'

语法错误 (操作符丢失) 在查询表达式 'distinct g_name' 中。

/ecool/index.asp,行91
似乎distinct和top不能共存,
1、请问为什么不能共存?
2、有什么解决的办法?
麻烦各位大侠不吝赐教,小弟在此先谢过!
...全文
1173 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
jerryf 2005-04-15
  • 打赏
  • 举报
回复
谢谢各位的热心帮忙,郁闷发帖,满意结帖,:)
wandering_hawk 2005-04-15
  • 打赏
  • 举报
回复
underone(underone)
看了你的回答我有个新的问题

如果是我要取前10条记录然后再distinct该怎么写?
qiqunet 2005-04-15
  • 打赏
  • 举报
回复


select sum(price) as 新字段名 from abc

然后就可以
变量=rs("新字段名")
qiqunet 2005-04-15
  • 打赏
  • 举报
回复


select sum(price) as 新字段名 from abc

jerryf 2005-04-15
  • 打赏
  • 举报
回复
可以了,谢谢楼上的大哥。
小弟还有一个问题,请问select sum(price) from abc,怎么用asp语句把这个sum的值取出来?
underone 2005-04-15
  • 打赏
  • 举报
回复
select sum(price) as price from abc

objRs("price")
yonghengdizhen 2005-04-15
  • 打赏
  • 举报
回复
用派生表查询
enjsky 2005-04-15
  • 打赏
  • 举报
回复
select sum(price) as all_count from abc

取的时候就用

rs("all_count")
itzhiren 2005-04-15
  • 打赏
  • 举报
回复
select distinct top 10 g_name,g_image_m,g_price from goods where g_isnew='y'
underone 2005-04-14
  • 打赏
  • 举报
回复
select distinct top 6 g_name,g_image_m,g_price from goods where g_isnew='y'
kernelv8 2005-04-14
  • 打赏
  • 举报
回复
up
jerryf 2005-04-14
  • 打赏
  • 举报
回复
自己顶一下
Zerolone 2005-04-14
  • 打赏
  • 举报
回复
关注一下, 也想知道

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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