易截截图软件、单文件、免安装、纯绿色、仅160KB

求一SQL语句 - 其他数据库开发 / MySQL/Postgresql

有一订单表
SQL code:
t_orders{
oid,
user_id,
booking_time
}


用户拥有的订单数
SQL code:
select o.user_id, count(o.oid) as amount from t_orders o where booking_time between (time1, between2)
group by o.user_id order by amount

====================
user_id amount
10001 1
10002 1
10004 2
10003 3
10007 3
10009 3
10011 3
10005 5
10006 8
10008 8
10010 8

现需统计拥有订单数目相同的用户数
希望结果:
orderAmount users
1 2
2 1
3 4
5 1
8 3

麻烦哪位帮写下能得出上面统计结果的SQL?
SQL code:

select tb.amount,count(*) users from
(select o.user_id, count(o.oid) as amount from t_orders o where booking_time between (time1, between2)
group by o.user_id) tb
group by tb.amount
order by tb.amount;



select amount,count(*) as users from 
(select o.user_id, count(o.oid) as amount from t_orders o where booking_time between (time1, between2)
group by o.user_id) t
group by amount
ord


相关问答:

mysql连接tomcat - Java / Web 开发

我已经按照教程上配置tomcat的server.xml
<Context path = "/POS" docBase = "POS" debug = "5" reloadable = "true" crossContext = "true" workDir = &quo ......

数据以xml格式返回 - MS-SQL Server / 应用实例

从数据库中查询一张表的数据
select 部门,姓名 from tb
如何才能生成下面的xml格式
XML code:
<folder state="unchecked" label="全部">
   <folder state="unchecked&qu ......

sqlserver错误 - MS-SQL Server / 疑难问题

sqlserver2005 建立的数据库,与手持pda传输数据,最近突然出现无法传递数据的问题,pda端提示的错误时outofmemoryexception,但是pda上面的容量没有问题,
sqlserver的日子上的错误如下:
日期 2010-1-25 14:45: ......

mysql字段提取 - 其他数据库开发 / MySQL/Postgresql

各位兄弟请教 下,在mysql中能不能实现这样一个功能,
一个字段A是储存一大段文字内容的,是英文,能不能通过MYSQL的查询之类的功能,来获得这个字段中 出现频率最高的十个单词,并将这十个单词做为新的字段储存
a ......

SQL server分解XML - MS-SQL Server / 应用实例

下面是XML初始文件内容
XML code:
<upd:Update xmlns:lar="http://schemas.microsoft.com/msus/2002/12/LogicalApplicabilityRules" xmlns:cmd="http://schemas.microsoft.com/msus/2002/12/Up ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号