当前位置:首页 » 编程语言 » sql条件查询

sql条件查询

发布时间: 2022-01-28 23:23:25

⑴ 求sql语句中带有条件的查询

通用写法

SELECTuid,
uname,
address,
(CASE
WHENphone1ISNOTNULLTHENphone1
WHENphone2ISNOTNULLTHENphone2
ELSEphone3
END)iphone
FROMusers;

oracle还可以这么写

SELECTuid,
uname,
address,
(NVL(phone1,NVL(phone2,phone3)))iphone
FROMusers;

⑵ SQL 多条件查询语句

select top 1 * from table where 许用合力 > 75 and 许用扭矩 > 10 and 传动滚筒直径 = 1000 order by 许用扭矩, 许用合力

--输出结果就是先符合条件数据,再按许用扭矩和许用合力的升序排列,然后选取第一条,即最近的一条数据。

⑶ sql多条件查询

where a=1 and b=2
where b=2 and c=3
where a=1 and b=2 and c=3

如果只满足其中一个
where a=1 or b=2 or c=3

⑷ 简单SQL多条件查询

select 结果=case when A<>'' then A
when B<>'' then B
when C<>'' then C
when D<>'' then D
else '都为空'
end
from 表

⑸ SQL多条件查询语句

select * from tab_name where 组号='001组' and to_char(日期,'yyyy-mm-dd')='2013-04-15' and 姓名1='小王'
union all
select * from tab_name where 组号='001组' and to_char(日期,'yyyy-mm-dd')='2013-04-15' and 姓名2='小王'
union all
select * from tab_name where 组号='001组' and to_char(日期,'yyyy-mm-dd')='2013-04-15' and 姓名3='小王'
union all
select * from tab_name where 组号='001组' and to_char(日期,'yyyy-mm-dd')='2013-04-15' and 姓名4='小王'

或者是:
select * from tab_name where 组号='001组' and to_char(日期,'yyyy-mm-dd')='2013-04-15' and 姓名1='小王' or 姓名2='小王' or 姓名3='小王' or 姓名4='小王'

⑹ 【SQL】根据条件查询数据

问题补充:

我纠正一下,以上问题,当数据加载的时候,能够根据前面的条件显示出数据来,但如果其中参杂其他条件的时候,以上语句就查询不准确了?

比如我想根据操作员的姓名,再结合上面条件查询,结果不准确,这是为什么?

---------
加上括号,再加上其它条件如:

(3 in([result1],[result2],[result3],[result4],[result5])
or
1 in([result1],[result2],[result3],[result4],[result5])
) and ...........
个人喜欢这样做简洁

⑺ SQL多条件语句查询怎么写

我用过一个笨方法,定义多个局部变量,每个变量为一种查询条件,然后在winform中根据筛选条件进行变量的合并与赋值,得到最终的查询条件,然后再执行sql语句就行啦。俺自学的.net,分享一下当时折腾了一个星期的心得,呵呵

⑻ sql怎么用查询结果作为条件进行查询

1、查询数据库表的所有字段并直接使用select语句。从数据库表中选择*。

⑼ sql条件判断查询

假设2个表中都有字段 月份 TheMonth 和数据 TheData ,
select sum(TheData) from
(select isnull(accvouch.TheData,(select Accsum.TheData from Accsum where 月份=1)) from Accvouch where 月份=1
union all
select Accvouch.TheData from Accvouch where 月份>1) as NewTable where 1=1

热点内容
ps4各个服务器有什么区别 发布:2024-05-06 14:10:38 浏览:484
手机上怎么玩韩国服务器游戏 发布:2024-05-06 14:10:20 浏览:58
频繁的解压缩 发布:2024-05-06 14:09:30 浏览:820
怎么在红帽上装c语言编译器 发布:2024-05-06 13:58:38 浏览:507
linuxtomcat设置 发布:2024-05-06 13:50:11 浏览:28
c语言需要什么基础 发布:2024-05-06 13:46:10 浏览:687
python利器 发布:2024-05-06 13:33:56 浏览:731
ts代码编译成umd 发布:2024-05-06 13:13:38 浏览:724
粮库存储粮种类 发布:2024-05-06 13:11:26 浏览:52
一般网络的dns服务器是什么 发布:2024-05-06 13:02:43 浏览:153