(Select RTRIM(count(id)) as 购气次数 From A
where (time Between '2008-01-05' and'2008-03-06') and buy=0
where (time Between '2008-01-05' and'2008-03-06') and buy=0
解决方案 »
- 请教一个SELECT语句
- SQL 语句 求助
- 数据库操作 如何向F_Number这一列插入形如'FFF20120001' 前7位不变后四位递增
- ●●●●●●●查 询 并 添 加 记 录。高 手 请 进。分 不 够 还 有。~~~~
- 这个问题在VB版问了两次了,还是没人解决,到这里试试运气
- 欢迎做过出程序员的同志赐教!(关于vfp)
- SQLServer2000中企业管理器问题“未找到提供者,可能未被正确安装”???
- 如何从数据库中高效的取出需要的记录?
- 保留小数???
- 如何统计某个字段中的某个字符数量,有无函数,急急!!
- 复杂的for xml语句,生成合适的XML树形菜单。弄了一天多了
- 远程访问!!!!
select [name] from 表A
where [name] not in
(select [name] from 表A where [time] Between '2008-01-05' and'2008-03-06' )
id name buy time
1 x1 10 2008-01-01
2 x2 20 2008-01-02
3 x3 10 2008-01-03
4 x4 10 2008-01-04
5 x5 10 2008-01-05
6 x4 10 2008-01-05
7 x1 10 2008-01-06
我想查询2008-01-05 到2008-01-06之间的购买量(buy)为0的用户
结果应该为x2,x3
(Select RTRIM(count(id)) as 购气次数 From A
where time Between '2008-01-05' and'2008-03-06' and buy=0 这样好象不行,问题似乎出在这里and buy=0,但不知道怎么表示这段时间没有购买的用户 select name from tb where time between '2008-01-05' and'2008-03-06'
group by name having sum(buy) = 0
insert into tb values(1, 'x1', 10 , '2008-01-01')
insert into tb values(2, 'x2', 20 , '2008-01-02')
insert into tb values(3, 'x3', 10 , '2008-01-03')
insert into tb values(4, 'x4', 10 , '2008-01-04')
insert into tb values(5, 'x5', 10 , '2008-01-05')
insert into tb values(6, 'x4', 10 , '2008-01-05')
insert into tb values(7, 'x1', 10 , '2008-01-06')
insert into tb values(8, 'x6', 0 , '2008-01-05') --我增加的测试数据
insert into tb values(9, 'x6', 0 , '2008-01-06') --我增加的测试数据
goselect name from tb where time between '2008-01-05' and'2008-03-06'
group by name having sum(buy) = 0drop table tb/*
name
----------
x6(所影响的行数为 1 行)
*/
create table tb(id int, name varchar(10), buy int, time datetime)
insert into tb values(1, 'x1', 10 , '2008-01-01')
insert into tb values(2, 'x2', 20 , '2008-01-02')
insert into tb values(3, 'x3', 10 , '2008-01-03')
insert into tb values(4, 'x4', 10 , '2008-01-04')
insert into tb values(5, 'x5', 10 , '2008-01-05')
insert into tb values(6, 'x4', 10 , '2008-01-05')
insert into tb values(7, 'x1', 10 , '2008-01-06')
goselect distinct name from tb where name not in
(
select name from tb where time between '2008-01-05' and'2008-03-06' group by name having sum(buy) <> 0
) drop table tb/*
name
----------
x2
x3(所影响的行数为 2 行)
*/