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

Delphi小叮当 2013-12-24 04:25:17
我的数据库库中有一个表名称是 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语句应该如何写呢?
...全文
276 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Delphi小叮当 2013-12-24
  • 打赏
  • 举报
回复
select * from part_words where words_unit in(unit1,unit2)

lhy 2013-12-24
  • 打赏
  • 举报
回复
words_unit字段不可能同时既是'unit2'又是'unit1' 可以用or把这几个连起来吧 比如
select count(*) as recordcount from part_words where words_unit = 'unit2' or  words_unit='unit1'
Oraclers 2013-12-24
  • 打赏
  • 举报
回复
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]'

2,498

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧