我想到使用rs.recordcound,可是这个只能统计纪录数,不知道应该怎么用,请高手赐教为谢!
6 个解决方案
#1
事实
#2
select count(*) from A where dcry1 <>'' where datediff("M",sj,date())=1
意思是统计最近一个月dcry1不为空的数量
access中日期用#2008-1-29#
ms sql 中日期用'2008-1-29'
意思是统计最近一个月dcry1不为空的数量
access中日期用#2008-1-29#
ms sql 中日期用'2008-1-29'
#3
select distinct dcry1 from 表A
union
select distinct dcry2 from 表A
#4
CREATE TABLE test
(
ajbh INT NOT NULL ,
sj DATETIME,
dcry1 VARCHAR(20),
dcry2 VARCHAR(20)
)
INSERT INTO test VALUES(1,GETDATE(),'aa','bb');
INSERT INTO test VALUES(2,GETDATE(),'aa','bb');
INSERT INTO test VALUES(3,GETDATE(),'aa','bb');
INSERT INTO test VALUES(4,GETDATE(),'aa1','bb');
INSERT INTO test VALUES(5,GETDATE(),'aa','bb2');
INSERT INTO test VALUES(6,GETDATE(),'aa','bb1');
INSERT INTO test VALUES(7,GETDATE(),'aa2','bb2');
INSERT INTO test VALUES(8,GETDATE(),'aa','bb');
INSERT INTO test VALUES(9,GETDATE(),'','bb');
INSERT INTO test VALUES(10,GETDATE(),'aa','');
INSERT INTO test VALUES(11,GETDATE(),'aa','bb');
INSERT INTO test VALUES(12,GETDATE(),'','bb3');
INSERT INTO test VALUES(13,GETDATE(),'aa3','bb');
INSERT INTO test VALUES(14,GETDATE(),'aa','');
SELECT * FROM test
select distinct COUNT(dcry1) from test WHERE dcry1 <>''
union
select distinct count(dcry2) from test WHERE dcry2 <>''
SELECT COUNT(*) FROM (select distinct dcry1 from test
union
select distinct dcry2 from test WHERE dcry1 <>'') a
DROP TABLE test
#5
楼上的修改了一下
CREATE TABLE test
(
ajbh INT NOT NULL ,
sj DATETIME,
dcry1 VARCHAR(20),
dcry2 VARCHAR(20)
)
INSERT INTO test VALUES(1,GETDATE(),'aa','bb');
INSERT INTO test VALUES(2,GETDATE(),'aa','bb');
INSERT INTO test VALUES(3,GETDATE(),'aa','bb');
INSERT INTO test VALUES(4,GETDATE(),'aa1','bb');
INSERT INTO test VALUES(5,GETDATE(),'aa','bb2');
INSERT INTO test VALUES(6,GETDATE(),'aa','bb1');
INSERT INTO test VALUES(7,GETDATE(),'aa2','bb2');
INSERT INTO test VALUES(8,GETDATE(),'aa','bb');
INSERT INTO test VALUES(9,GETDATE(),'','bb');
INSERT INTO test VALUES(10,GETDATE(),'aa','');
INSERT INTO test VALUES(11,GETDATE(),'aa','bb');
INSERT INTO test VALUES(12,GETDATE(),'','bb3');
INSERT INTO test VALUES(13,GETDATE(),'aa3','bb');
INSERT INTO test VALUES(14,GETDATE(),'aa','');
SELECT COUNT(*) FROM (select distinct dcry1 from test
union
select distinct dcry2 from test WHERE dcry1 <>'') a
DROP TABLE test
CREATE TABLE test
(
ajbh INT NOT NULL ,
sj DATETIME,
dcry1 VARCHAR(20),
dcry2 VARCHAR(20)
)
INSERT INTO test VALUES(1,GETDATE(),'aa','bb');
INSERT INTO test VALUES(2,GETDATE(),'aa','bb');
INSERT INTO test VALUES(3,GETDATE(),'aa','bb');
INSERT INTO test VALUES(4,GETDATE(),'aa1','bb');
INSERT INTO test VALUES(5,GETDATE(),'aa','bb2');
INSERT INTO test VALUES(6,GETDATE(),'aa','bb1');
INSERT INTO test VALUES(7,GETDATE(),'aa2','bb2');
INSERT INTO test VALUES(8,GETDATE(),'aa','bb');
INSERT INTO test VALUES(9,GETDATE(),'','bb');
INSERT INTO test VALUES(10,GETDATE(),'aa','');
INSERT INTO test VALUES(11,GETDATE(),'aa','bb');
INSERT INTO test VALUES(12,GETDATE(),'','bb3');
INSERT INTO test VALUES(13,GETDATE(),'aa3','bb');
INSERT INTO test VALUES(14,GETDATE(),'aa','');
SELECT COUNT(*) FROM (select distinct dcry1 from test
union
select distinct dcry2 from test WHERE dcry1 <>'') a
DROP TABLE test
#6
谢谢yun_feiyang_77 、谢谢各位!
yun_feiyang_77 ,你发贴时我已经处理结贴了,抱歉~~我加你好吗?有问题好请教你
yun_feiyang_77 ,你发贴时我已经处理结贴了,抱歉~~我加你好吗?有问题好请教你
#1
事实
#2
select count(*) from A where dcry1 <>'' where datediff("M",sj,date())=1
意思是统计最近一个月dcry1不为空的数量
access中日期用#2008-1-29#
ms sql 中日期用'2008-1-29'
意思是统计最近一个月dcry1不为空的数量
access中日期用#2008-1-29#
ms sql 中日期用'2008-1-29'
#3
select distinct dcry1 from 表A
union
select distinct dcry2 from 表A
#4
CREATE TABLE test
(
ajbh INT NOT NULL ,
sj DATETIME,
dcry1 VARCHAR(20),
dcry2 VARCHAR(20)
)
INSERT INTO test VALUES(1,GETDATE(),'aa','bb');
INSERT INTO test VALUES(2,GETDATE(),'aa','bb');
INSERT INTO test VALUES(3,GETDATE(),'aa','bb');
INSERT INTO test VALUES(4,GETDATE(),'aa1','bb');
INSERT INTO test VALUES(5,GETDATE(),'aa','bb2');
INSERT INTO test VALUES(6,GETDATE(),'aa','bb1');
INSERT INTO test VALUES(7,GETDATE(),'aa2','bb2');
INSERT INTO test VALUES(8,GETDATE(),'aa','bb');
INSERT INTO test VALUES(9,GETDATE(),'','bb');
INSERT INTO test VALUES(10,GETDATE(),'aa','');
INSERT INTO test VALUES(11,GETDATE(),'aa','bb');
INSERT INTO test VALUES(12,GETDATE(),'','bb3');
INSERT INTO test VALUES(13,GETDATE(),'aa3','bb');
INSERT INTO test VALUES(14,GETDATE(),'aa','');
SELECT * FROM test
select distinct COUNT(dcry1) from test WHERE dcry1 <>''
union
select distinct count(dcry2) from test WHERE dcry2 <>''
SELECT COUNT(*) FROM (select distinct dcry1 from test
union
select distinct dcry2 from test WHERE dcry1 <>'') a
DROP TABLE test
#5
楼上的修改了一下
CREATE TABLE test
(
ajbh INT NOT NULL ,
sj DATETIME,
dcry1 VARCHAR(20),
dcry2 VARCHAR(20)
)
INSERT INTO test VALUES(1,GETDATE(),'aa','bb');
INSERT INTO test VALUES(2,GETDATE(),'aa','bb');
INSERT INTO test VALUES(3,GETDATE(),'aa','bb');
INSERT INTO test VALUES(4,GETDATE(),'aa1','bb');
INSERT INTO test VALUES(5,GETDATE(),'aa','bb2');
INSERT INTO test VALUES(6,GETDATE(),'aa','bb1');
INSERT INTO test VALUES(7,GETDATE(),'aa2','bb2');
INSERT INTO test VALUES(8,GETDATE(),'aa','bb');
INSERT INTO test VALUES(9,GETDATE(),'','bb');
INSERT INTO test VALUES(10,GETDATE(),'aa','');
INSERT INTO test VALUES(11,GETDATE(),'aa','bb');
INSERT INTO test VALUES(12,GETDATE(),'','bb3');
INSERT INTO test VALUES(13,GETDATE(),'aa3','bb');
INSERT INTO test VALUES(14,GETDATE(),'aa','');
SELECT COUNT(*) FROM (select distinct dcry1 from test
union
select distinct dcry2 from test WHERE dcry1 <>'') a
DROP TABLE test
CREATE TABLE test
(
ajbh INT NOT NULL ,
sj DATETIME,
dcry1 VARCHAR(20),
dcry2 VARCHAR(20)
)
INSERT INTO test VALUES(1,GETDATE(),'aa','bb');
INSERT INTO test VALUES(2,GETDATE(),'aa','bb');
INSERT INTO test VALUES(3,GETDATE(),'aa','bb');
INSERT INTO test VALUES(4,GETDATE(),'aa1','bb');
INSERT INTO test VALUES(5,GETDATE(),'aa','bb2');
INSERT INTO test VALUES(6,GETDATE(),'aa','bb1');
INSERT INTO test VALUES(7,GETDATE(),'aa2','bb2');
INSERT INTO test VALUES(8,GETDATE(),'aa','bb');
INSERT INTO test VALUES(9,GETDATE(),'','bb');
INSERT INTO test VALUES(10,GETDATE(),'aa','');
INSERT INTO test VALUES(11,GETDATE(),'aa','bb');
INSERT INTO test VALUES(12,GETDATE(),'','bb3');
INSERT INTO test VALUES(13,GETDATE(),'aa3','bb');
INSERT INTO test VALUES(14,GETDATE(),'aa','');
SELECT COUNT(*) FROM (select distinct dcry1 from test
union
select distinct dcry2 from test WHERE dcry1 <>'') a
DROP TABLE test
#6
谢谢yun_feiyang_77 、谢谢各位!
yun_feiyang_77 ,你发贴时我已经处理结贴了,抱歉~~我加你好吗?有问题好请教你
yun_feiyang_77 ,你发贴时我已经处理结贴了,抱歉~~我加你好吗?有问题好请教你