Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 冲浪宝典 > 网络资源 > distinct 和 order by 的 矛盾
【标  题】:distinct 和 order by 的 矛盾
【关键字】:distinct,order,by
【来  源】:http://blog.csdn.net/alexjjf/archive/2007/04/19/1570150.aspx

distinct 和 order by 的 矛盾

Your Ad Here

select distinct cont_id from cms_contentiteminfo t order by  cast  (t.click   as   int) desc

上面这句报错ORA-1791,not a SELECTED expression

select distinct cont_id ,cast  (t.click   as   int) as c from cms_contentiteminfo t order by  cast  (t.click   as   int) desc

查出的结果是有重复记录的

cont_id   c

185337 1517
185639 1003
185586 985
185337 967
185641 937
185337 899
185639 832
185641 832
185641 727
185283 649
185144 605
185586 588
185639 564
185216 547
185586 508
185283 492
185144 422
185283 421
185216 378
185217 369
185144 346
185626 309
185217 303
192278 254

修改为

select distinct cont_id,max(cast (t.click  as   int)) c from cms_contentiteminfo t group   by cont_id order by  c desc

查询结果

cont_id  c

185337 1517
185639 1003
185586 985
185641 937
185283 649
185144 605
185216 547
185217 369
185626 309
192278 254
185145 234
191809 214
185286 191
190484 190
185642 190
190487 180
185287 171
190486 162
192483 146
189151 138
191253 118
177607 117
192704 116
185140 115

cont-id重复的记录就可以去掉了

 

 

【转载】使用sql-server进行分布式查询:【上一篇】
sql中字符串型数字排序:【下一篇】
【相关文章】
  • Ruby on Rails 与 Grails 之比较(一):简介
  • ruby/rails
  • 微软WebService之MapPoint分析手记(一):MapPoint试用Step By Step
  • 创建自己的ruby Gems
  • mysql for linux傻瓜式安装 step by step
  • Platform Manager cannot create the communication streams needed by the debugger.
  • 关键词Byte相关知识与实用类的深入理解(流操作,加密处理,图像处理等的基础准备)
  • Ruby创造的奇迹
  • 专访:Ruby能否成为第二个Java
  • 男人眼泪中的 Ruby (一)
  • 【随机文章】
  • Authorware制作倒计时牌
  • 苍之涛所有大小boss轻松过关技巧
  • 自解密的加密程序的制作
  • Maya UV 编辑实例系列(4)使用Fix Texture Warp选项
  • INFORMIX-ONLINE数据库三种备份方法的选择
  • 真正的网上创业机会来了!
  • 用JavaScript控制不允许用户选择文字复制文件
  • 2006年Java One大会10大Java SE 分会场
  • 字符串的一些操作
  • 磁带驱动器的使用
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 bbb软讯网络 All Rigths Reserved.