select bookid from tablename group by bookid having count(*)= (select max(times) from (select bookid,count(*) as times from tablename group by bookid) a)
select top 1 bookid,count(*) as times from tablename group by bookid order by times desc
-- 你这个是什么语法?有点看不懂 select top bookid from tablename group by bookid order by count(1)
select top 1 bookid from tablename group by bookid order by count(1) desc
create table a(bookid varchar(10),bookname varchar(20)) insert into a select '001','1111' union all select '002','2222' union all select '003','3333' union all select '001','1111' union all select '002','2222' union all select '001','1111' select top 1 bookid,count(bookid) from a group by bookid order by count(bookid) desc drop table a(所影响的行数为 6 行)bookid ---------- ----------- 001 3(所影响的行数为 1 行)
select top 1 count(*) from tablename group by bookid order by count(*) desc
as times`的用发是怎么样的?
order by后面可以用聚集函数吗?
就是把count(*) --(bookid借出的次數)賦一個字段名啊,
如果用的是group by ,order by后面就可以用聚集函数
如果用的是group by ,order by后面就可以用聚集函数,什么意思?有group by,后面的ordr by就可以用聚集函数了???????
select top 1 count(*) ,title into :z,:name from tablename group by bookid order by count(*) desc
(select max(times) from
(select bookid,count(*) as times from tablename group by bookid) a)
select top bookid from tablename group by bookid order by count(1)
insert into a select '001','1111'
union all select '002','2222'
union all select '003','3333'
union all select '001','1111'
union all select '002','2222'
union all select '001','1111'
select top 1 bookid,count(bookid) from a group by bookid order by count(bookid) desc
drop table a(所影响的行数为 6 行)bookid
---------- -----------
001 3(所影响的行数为 1 行)
into :z,:name
from tablename
group by bookid
order by count(*) desc