关于select数据

Lapuasi 2003-08-30 12:58:37
table如下

id f1 f2
1 1 1
2 1 1
3 2 1
4 2 1
5 3 1

想查询f1字段中为1的记录数,和为2的记录数,用一个sql语句。

谢了
...全文
13 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
Lapuasi 2003-08-30
  • 打赏
  • 举报
回复
对,在一个recordset中得到f1字段为1记录数,和不为1的记录数。
select sum(case when f1=1 then 1 else 0 end),sum(case when f1=2 then 1 else 0 end)
from table

报错!
laers 2003-08-30
  • 打赏
  • 举报
回复
select count(*)as 0 from table where f1 in (1,2)

response write rs("munbers")
cloudchen 2003-08-30
  • 打赏
  • 举报
回复
搞错,是不是想分别取count

select sum(case when f1=1 then 1 else 0 end),sum(case when f1=2 then 1 else 0 end)
from table
cloudchen 2003-08-30
  • 打赏
  • 举报
回复
select count(*) from table where f1 in (1,2)
wolf004 2003-08-30
  • 打赏
  • 举报
回复
f1是数字型,如果是字符型的话加'号!
wolf004 2003-08-30
  • 打赏
  • 举报
回复
sql="select * from table where f1 in (1,2)"

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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