注册 登录
编程论坛 SQL Server论坛

计算表中总数的问题。。。。。。。。。

ysf0181 发布于 2006-12-04 16:34, 665 次点击

怎么计算表中有条件记录的总数!!!

例如,a 表中的两个字段:a_true a_user a_true字段为数字:取值1、2、3
1 123 a_user字段为用户:很多我就不说了。例如,123 ,abc等
2 123
1 123
3 123
2 123
3 abc
2 abc
1 abc
2 abc

首先,我先查询出123用户在a表中所有记录:select * from a where a_user=123
那我要再查询123用户在a表中的字段a_true的值为1的记录总数,,,这该怎么写哦...求助中。。谢谢。。。。。。。

5 回复
#2
angeloc2006-12-04 16:46
select count(*) from a where a_user=123 and a_true=1
#3
ysf01812006-12-05 09:12
我执行了。提示错误呀。。。。。。。。。。。请问如果在asp中。。。。。我已经查询了
select * from a where a_user=123 该用户的记录。。。
再统计123的a_true=1的用户记录有多少,我该怎么写?谢谢。。。。。。。。。。。
#4
angeloc2006-12-05 09:37
以下是引用ysf0181在2006-12-5 9:12:22的发言:
我执行了。提示错误呀。。。。。。。。。。。请问如果在asp中。。。。。我已经查询了
select * from a where a_user=123 该用户的记录。。。
再统计123的a_true=1的用户记录有多少,我该怎么写?谢谢。。。。。。。。。。。

不管你已经查询了什么,这和下一次查询是没有关系的。

#5
wsn2006-12-05 11:05
select count(*) as recodercount from a where a_user=123 and a_true=1
不会错的
#6
ysf01812006-12-05 16:11
谢谢。。测试中。。。。。。。。。
1