球一句SQL查询 - .NET技术 / ASP.NET
select count(autoID) as linecount,webgroup from flinkIn group by webgroup order by linecount
分组结果如下,可如何取出最小值30的webGroup1003linecount,webgroup
30 1003
500 1002
524 1001
这写取出的是30而不是1003
select min(linecount) from (select count(autoID) as linecount,webgroup from flinkIn group by webgroup) as tmptable
应该怎么写啊
混乱!!
给出表结构,
和你最终要的数据结构!!
top 1不行么?
既然已经是升序 就最小的 top 1就足够了啊
linecount,webgroup
30 1003
500 1002
524 1001
要的是1003啊
取出的1003在给变量,存储过程中的
--30 1003
--500 1002
--524 1001
declare @tmptb table(字段1 int,字段2 int)
insert into @tmptb select 30,1003
union all select 500,1002
union all select 524,1001
select * from @tmptb where 字段1=(select min(字段1) from @tmptb)
如果linecount=30只有一行
select top 1 * from (select count(autoID) as linecount,webgroup from flinkIn group by webgroup) order by linecount
如果有多行
select * from (select count(autoID) as linecount,webgroup from flinkIn group by webgroup) t1
where t1.linecount = (select min(linecount) from (select count(autoID) as linecount,webgroup from flinkIn group by webgroup)
SQL code
Code highlighting produced by Actipro CodeHighlighter (freeware)
相关问答:
可能因为工作的原因 接触数据库这块比较少,之前都是做程序这块,数据库这块都有专门的人来做 分工都很明细 所以对数据库这一块完全不了解。前段时间 去面试了几家公司 几乎都是在数据库这块挂掉的 连个简单的SQ ......
从数据库中查询一张表的数据
select 部门,姓名 from tb
如何才能生成下面的xml格式文件
<folder state="unchecked" label="全部">
<folder state="unchecked" isBra ......
现在有两张表:文章主表A(articleId,articleTitle),文章评论表B(commentId,articleId,commentTitle)
现在我想实现这样的功能:列出文章列表,其中每篇文章标题下面列出此文章的前2个文章评论,请问sql语句怎么写啊 ......
如何在SQL2005中设定定时作业,比如说定时清理某些表的数据,
或者是定时的将某些表的数据导出excel!
在线等待,急急急,最好是详细步骤!
之前我做的作业有点问题!
帮UP
参考:http://hi.baidu.com/toiota ......
tab1 字段:billdate,goodsid,incount,inmoney,outcount,outmoney,endprice,endcount,endamt
tab2 字段:goodsid,goodskind(商品类型)
tab3 字段:goodskind(商品类型),kindname
结果:
得到商品类型在一段时间 ......