zoukankan      html  css  js  c++  java
  • 统计表中 重复出现 XX次以上的数据

    在平时使用数据库查询数据时 经常会遇到查询表中出现XX次以上的数据  以前自己遇到就直接百度  然后拿来就用  在过段时间遇到就懵逼了 还得百度。。。。

    so  还是加深理解下  省的以后遇到再次一脸懵逼。

    大致的写法:

    select * from 表名 where 字段名  in ( select 字段名  from表名  group by 字段名    having count(*)>出现次数) order by update_time desc

    也可以直接写:

    select 字段名  from表名  group by 字段名    having count(*)>出现次数

    这么写 返回的数据只有一列   看上去不是很直观。

    2 统计最近几日支付金额最大的前10个用户

    select top 10 iUserId,sum(fTotalPrice)as total  from ymt_orders where iTradingStatus=4 and  dPaidTime<=GETDATE() -500 group by iUserId order by total   desc  

  • 相关阅读:
    CodeForces
    网络流
    poj 2185
    树的分治学习
    数位DP
    URAL 1969. Hong Kong Tram
    hdu 4759 Poker Shuffle
    hdu3712 Detector Placement
    分块思想
    莫比乌斯反演
  • 原文地址:https://www.cnblogs.com/dwtt/p/7603017.html
Copyright © 2011-2022 走看看