求一ms sql

phoebuswei 2008-12-18 05:14:57
有结果集合
select c1 from table where c1 between A and B
集合
A
A
A
A
B
B
B
B
B
想要得到下面结果
4 A
5 B
...全文
101 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
phoebuswei 2008-12-19
  • 打赏
  • 举报
回复
没有能执行的,结贴
龙扬天 2008-12-18
  • 打赏
  • 举报
回复
create table xc
(id int identity(1,1),c1 varchar(2))
insert into xc(c1)
select 'B'union
select 'A'union
select 'A'union
select 'A'union
select 'A'union
select 'B'union
select 'B'union
select 'B'union
select 'B'
select * from xc
1 A
2 B
3 A
4 A
5 A
6 A
7 B
8 B
9 B
select count(*) as 个数,c1 from xc group by c1
5 A
4 B
ChinaITOldMan 2008-12-18
  • 打赏
  • 举报
回复
SELECT c1,COUNT(*) AS cnt
FROM [table]
WHERE c1 BETWEEN 'A' AND 'B'
GROUP BY c1
等不到来世 2008-12-18
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 phoebuswei 的回复:]
需求更新
c1 是类型DateTime
要按照 没小时分组
2008-11-2-20:00
2008-11-2-20:00
2008-11-2-21:00
2008-11-2-23:00
2008-11-2-23:00
2008-11-2-23:00
结果集合
2,2008-11-2-20:00
1,2008-11-2-21:00
3,2008-11-2-23:00
[/Quote]
select count(*),c1
from table
group by c1
phoebuswei 2008-12-18
  • 打赏
  • 举报
回复
需求更新
c1 是类型DateTime
要按照 没小时分组
2008-11-2-20:00
2008-11-2-20:00
2008-11-2-21:00
2008-11-2-23:00
2008-11-2-23:00
2008-11-2-23:00
结果集合
2,2008-11-2-20:00
1,2008-11-2-21:00
3,2008-11-2-23:00
中国风 2008-12-18
  • 打赏
  • 举报
回复
c1字符串沒有大小關系時用in
中国风 2008-12-18
  • 打赏
  • 举报
回复
select c1,count(*) con from table where c1 in('A','B') group by c1
dawugui 2008-12-18
  • 打赏
  • 举报
回复
select count(*) , c1 from table where c1 between 'A' and 'B' group by c1
dawugui 2008-12-18
  • 打赏
  • 举报
回复
[Quote=引用楼主 phoebuswei 的帖子:]
有结果集合
select c1 from table where c1 between A and B
集合
A
A
A
A
B
B
B
B
B
想要得到下面结果
4 A
5 B
[/Quote]
select count(*) , c1 from table where c1 between A and B  group by c1

liangCK 2008-12-18
  • 打赏
  • 举报
回复
SELECT c1,COUNT(*) AS cnt
FROM [table]
WHERE c1 BETWEEN 'A' AND 'B'
GROUP BY c1

34,576

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧