当前位置:首页 » 编程语言 » 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

热点内容
app什么情况下找不到服务器 发布:2025-05-12 15:46:25 浏览:714
php跳过if 发布:2025-05-12 15:34:29 浏览:467
不定时算法 发布:2025-05-12 15:30:16 浏览:131
c语言延时1ms程序 发布:2025-05-12 15:01:30 浏览:166
动物园灵长类动物配置什么植物 发布:2025-05-12 14:49:59 浏览:737
wifi密码设置什么好 发布:2025-05-12 14:49:17 浏览:150
三位数乘两位数速算法 发布:2025-05-12 13:05:48 浏览:399
暴风影音缓存在哪里 发布:2025-05-12 12:42:03 浏览:545
access数据库exe 发布:2025-05-12 12:39:04 浏览:632
五开的配置是什么 发布:2025-05-12 12:36:37 浏览:367