首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

sql语句同一字段多条件查询的有关问题

2013-12-26 
sql语句同一字段多条件查询的问题我的数据库库中有一个表名称是 part_words表中有一个字段是 words_unit在

sql语句同一字段多条件查询的问题
我的数据库库中有一个表名称是 part_words
表中有一个字段是 words_unit
在这个数据库中包含了很多数据,数据条中数据库在words_unit这个字段有unit1-unit10 这10个单元的内容

我现在想查询出Unit1和Unit2和Unit3 这3个单元的所有数据内容的总数

请问sql语句应该如何查询

我写的是 
select count(*) as recordcount from part_words where words_unit = 'unit2' and  words_unit='unit1'

发现数据库中的返回结果是0

请问这条SQL语句应该如何写呢?

[解决办法]
select count(*) as recordcount from part_words where words_unit = 'unit2' Or  words_unit='unit1'
或者:
select count(*) as recordcount from part_words where words_unit like 'unit[123]'
[解决办法]
words_unit字段不可能同时既是'unit2'又是'unit1'
可以用or把这几个连起来吧
比如

select count(*) as recordcount from part_words where words_unit = 'unit2' or  words_unit='unit1'

热点排行