这个 SQL 语句怎样写?(50分)

  • 主题发起人 主题发起人 apple058
  • 开始时间 开始时间
A

apple058

Unregistered / Unconfirmed
GUEST, unregistred user!
申请 受理 完成 销毁
张三 1 2 0 4
李四 2 0
王武 1 2 2 4
赵六 3 3 0 0
刘明 1 1 1 3

我现在要的数据是: 每行中 各个字段的值 只要有一个为 0 ,这一行我就需要

所以 这里 1,2,4 行为需要的数据
 
简单
select * from tab where 申请*受理*完成*销毁=0
如果null算0就 改成 isnull()....0
不算就 isnull......1
 
什么数据类型?
where 申请+受理+完成+销毁 like '%0%'
 
To ysai:
可是有的数据库不支持isnull函数啊:)
TO cxz9:
这样效率是否太低?:)
 
ysai:
你好,谢谢你回答我的问题,但是我没有搞懂你是怎么想的,能说说一二吗?
还有我的那个 0, 1,2,3 等不是整形 而是字符类型也!
 
这样:
数值型 select * from tab where 申请*受理*完成*销毁=0
字符型 select * from tab where (申请=0 or 申请 is null) or (受理=0 or 受理 is null)
or (完成=0 or 完成 is null) or (销毁=0 or 销毁 is null)

 
这样可能简洁一些:
select * from tab where (申请+受理+完成+销毁 like '%0%') or
(申请 is null or 受理 is null or 完成 is null or 销毁 is null)

 
procedure TForm1.Button2Click(Sender: TObject);
var
temp:array of integer;
i,j:integer;
begin
adoquery1.sql.text:='select * from youtable';
adoquery1.open;
setlength(temp,adoquery1.recordcount);
adoquery1.first;
while not eof do
begin
for i:=0 to 3 do //列数-1
if adoquery1.fields.Value=0 then
begin
temp[j]:=j;
inc(j);
exit;//退出FOR
end;
ADOquery1.next;
end;
for i:=0 to j do
begin
ADOquery1.recno:=temp; //需要的行
//处理数据
end;
end;

测试一下,估计没错
 
第一次来大富翁,完全同意gun_zf
 
不完全同意gun_zf,如果
申请 受理 完成 销毁
张四 10 2 10 4

就不管用啦!
 
后退
顶部