A表: 1 2 aa 001 bb 001 cc 001 dd 002 现在就是说去2=001的数据但是1=aa的数据我不要,只显示bb和cc
你的SQL语句是什么,不可能不行啊?!mysql> select * from a; +------+------+ | f1 | f2 | +------+------+ | aa | 001 | | bb | 001 | | cc | 001 | | dd | 002 | +------+------+ 4 rows in set (0.00 sec)mysql> mysql> select * from a where f1 != 'aa'; +------+------+ | f1 | f2 | +------+------+ | bb | 001 | | cc | 001 | | dd | 002 | +------+------+ 3 rows in set (0.00 sec)mysql>
SELECT * from ttg1 where f2='001' and (f1)<>'aa'
贴出你语句,应该可以啊。mysql> select * from a where f1 != 'aa' and f2='001'; +------+------+ | f1 | f2 | +------+------+ | bb | 001 | | cc | 001 | +------+------+ 2 rows in set (0.00 sec)mysql> select * from a where f1 <> 'aa' and f2='001'; +------+------+ | f1 | f2 | +------+------+ | bb | 001 | | cc | 001 | +------+------+ 2 rows in set (0.00 sec)mysql>
create table test ( name varchar(50) )insert into test values('aaa'); insert into test values('bbb'); insert into test values('ccc');select * from test where name not in(select name from test where name like'%a%') 有点罗嗦,可以实现LZ的功能!
select * from t where name <>'xxx'
如果是创建表就将其约束,示例如下:create table t( id int primary key, name varchar(15) check(name<>"xxx") );如是查找就是:select * from t where name <>"xxx"希望有你要的!
1 2
aa 001
bb 001
cc 001
dd 002
现在就是说去2=001的数据但是1=aa的数据我不要,只显示bb和cc
+------+------+
| f1 | f2 |
+------+------+
| aa | 001 |
| bb | 001 |
| cc | 001 |
| dd | 002 |
+------+------+
4 rows in set (0.00 sec)mysql>
mysql> select * from a where f1 != 'aa';
+------+------+
| f1 | f2 |
+------+------+
| bb | 001 |
| cc | 001 |
| dd | 002 |
+------+------+
3 rows in set (0.00 sec)mysql>
+------+------+
| f1 | f2 |
+------+------+
| bb | 001 |
| cc | 001 |
+------+------+
2 rows in set (0.00 sec)mysql> select * from a where f1 <> 'aa' and f2='001';
+------+------+
| f1 | f2 |
+------+------+
| bb | 001 |
| cc | 001 |
+------+------+
2 rows in set (0.00 sec)mysql>
create table test
(
name varchar(50)
)insert into test values('aaa');
insert into test values('bbb');
insert into test values('ccc');select * from test where name not in(select name from test where name like'%a%')
有点罗嗦,可以实现LZ的功能!
id int primary key,
name varchar(15) check(name<>"xxx")
);如是查找就是:select * from t where name <>"xxx"希望有你要的!