select pcbsn, power from caltest where exists (
select sn, pcbsn from snandpcbsn where sn in
(select sn from packlist_br where work_order='1311-14010011')
)
and work_order='1311-13110057'
select pcbsn, power from caltest where work_order='1311-13110057'
楼主要了解exists的具体含义,exists()的表达式中,如果存在记录,那么条件就是 1 = 1,如果不存在,那么就是 1 = 0,再来看楼主的语句,如果exists的表达式
select sn, pcbsn from snandpcbsn where sn in
(select sn from packlist_br where work_order='1311-14010011')
这个查询存在相应记录,那么这个条件就是 1 = 1,那么查询语句可以看做是
select pcbsn, power from caltest
where 1 = 1 and work_order='1311-13110057'
进一步简化为
select pcbsn, power from caltest
where work_order='1311-13110057'
这个查询是否和第二个查询语句一样了。
#6
我使用
select pcbsn from snandpcbsn where exists
(select sn from packlist_br where work_order='1311-14010011' and packlist_br.sn=snandpcbsn.sn)
select * from caltest where pcbsn in(
select pcbsn from snandpcbsn where exists
(select sn from packlist_br where work_order='1311-14010011' and packlist_br.sn=snandpcbsn.sn)
)
#7
是不是packlist_br没有work_order这个字段
#8
是不是packlist_br没有work_order这个字段
试试这样呢:
select * from caltest
where pcbsn in(
select pcbsn from snandpcbsn where exists
(select sn from packlist_br where work_order='1311-14010011' and packlist_br.sn=snandpcbsn.sn)
)
and work_order='1311-14010011'
#9
修改一下:
select * from caltest
where pcbsn in(
select pcbsn from snandpcbsn where exists
(select sn from packlist_br where work_order='1311-14010011' and packlist_br.sn=snandpcbsn.sn)
)
and work_order='1311-13110057'
#10
修改一下:
select * from caltest
where pcbsn in(
select pcbsn from snandpcbsn where exists
(select sn from packlist_br where work_order='1311-14010011' and packlist_br.sn=snandpcbsn.sn)
)
and work_order='1311-13110057'
不好意思,我没对列排序, 所以看错了. 6#上的语句是正确的.
请问如何将
select * from caltest
where pcbsn in
的'in' 改成'exsits'?
#11
修改一下:
select * from caltest
where pcbsn in(
select pcbsn from snandpcbsn where exists
(select sn from packlist_br where work_order='1311-14010011' and packlist_br.sn=snandpcbsn.sn)
)
and work_order='1311-13110057'
不好意思,我没对列排序, 所以看错了. 6#上的语句是正确的.
请问如何将
select * from caltest
where pcbsn in
的'in' 改成'exsits'?
可以这样改成exists,
select * from caltest where exists (
select pcbsn from snandpcbsn where exists
(select sn from packlist_br where work_order='1311-14010011' and sn=snandpcbsn.sn)
and pcbsn=caltest.pcbsn
)
#12
请问各位,
上面语句, 数据行有重复(pcbsn)只显示一条记录, 如何修改?
#13
请问各位,
上面语句, 数据行有重复(pcbsn)只显示一条记录, 如何修改?
哦,你的是2000,还是2005呢,如果是2005,可以用下面的:
select *
from
(
select *,
ROW_NUMBER() over(partition by pcbsn order by getdate()) rownum
from caltest where exists (
select pcbsn from snandpcbsn where exists
(select sn from packlist_br where work_order='1311-14010011' and sn=snandpcbsn.sn)
and pcbsn=caltest.pcbsn
)
)t
where rownum = 1
#14
我使用的是MS SQL 2000, 没有row_number()函数.
我使用程序来处理吧.谢谢各位!
#1
我只执行这条,数据是正常的.
select sn, pcbsn from snandpcbsn where sn in
(select sn from packlist_br where work_order='1311-14010011')
#2
我只执行这条,数据是正常的.
select sn, pcbsn from snandpcbsn where sn in
(select sn from packlist_br where work_order='1311-14010011')
这个是对的,用的是in。
如果改成exists:
select sn, pcbsn from snandpcbsn where exists
(select 1 from packlist_br where work_order='1311-14010011' and sn = snandpcbsn.sn)
楼主要了解exists的具体含义,exists()的表达式中,如果存在记录,那么条件就是 1 = 1,如果不存在,那么就是 1 = 0,再来看楼主的语句,如果exists的表达式
select sn, pcbsn from snandpcbsn where sn in
(select sn from packlist_br where work_order='1311-14010011')
这个查询存在相应记录,那么这个条件就是 1 = 1,那么查询语句可以看做是
select pcbsn, power from caltest
where 1 = 1 and work_order='1311-13110057'
进一步简化为
select pcbsn, power from caltest
where work_order='1311-13110057'
这个查询是否和第二个查询语句一样了。
#6
我只执行这条,数据是正常的.
select sn, pcbsn from snandpcbsn where sn in
(select sn from packlist_br where work_order='1311-14010011')
这个是对的,用的是in。
如果改成exists:
select sn, pcbsn from snandpcbsn where exists
(select 1 from packlist_br where work_order='1311-14010011' and sn = snandpcbsn.sn)
我使用
select pcbsn from snandpcbsn where exists
(select sn from packlist_br where work_order='1311-14010011' and packlist_br.sn=snandpcbsn.sn)
select * from caltest where pcbsn in(
select pcbsn from snandpcbsn where exists
(select sn from packlist_br where work_order='1311-14010011' and packlist_br.sn=snandpcbsn.sn)
)
#7
是不是packlist_br没有work_order这个字段
#8
是不是packlist_br没有work_order这个字段
试试这样呢:
select * from caltest
where pcbsn in(
select pcbsn from snandpcbsn where exists
(select sn from packlist_br where work_order='1311-14010011' and packlist_br.sn=snandpcbsn.sn)
)
and work_order='1311-14010011'
#9
修改一下:
select * from caltest
where pcbsn in(
select pcbsn from snandpcbsn where exists
(select sn from packlist_br where work_order='1311-14010011' and packlist_br.sn=snandpcbsn.sn)
)
and work_order='1311-13110057'
#10
修改一下:
select * from caltest
where pcbsn in(
select pcbsn from snandpcbsn where exists
(select sn from packlist_br where work_order='1311-14010011' and packlist_br.sn=snandpcbsn.sn)
)
and work_order='1311-13110057'
不好意思,我没对列排序, 所以看错了. 6#上的语句是正确的.
请问如何将
select * from caltest
where pcbsn in
的'in' 改成'exsits'?
#11
修改一下:
select * from caltest
where pcbsn in(
select pcbsn from snandpcbsn where exists
(select sn from packlist_br where work_order='1311-14010011' and packlist_br.sn=snandpcbsn.sn)
)
and work_order='1311-13110057'
不好意思,我没对列排序, 所以看错了. 6#上的语句是正确的.
请问如何将
select * from caltest
where pcbsn in
的'in' 改成'exsits'?
可以这样改成exists,
select * from caltest where exists (
select pcbsn from snandpcbsn where exists
(select sn from packlist_br where work_order='1311-14010011' and sn=snandpcbsn.sn)
and pcbsn=caltest.pcbsn
)
#12
请问各位,
上面语句, 数据行有重复(pcbsn)只显示一条记录, 如何修改?
#13
请问各位,
上面语句, 数据行有重复(pcbsn)只显示一条记录, 如何修改?
哦,你的是2000,还是2005呢,如果是2005,可以用下面的:
select *
from
(
select *,
ROW_NUMBER() over(partition by pcbsn order by getdate()) rownum
from caltest where exists (
select pcbsn from snandpcbsn where exists
(select sn from packlist_br where work_order='1311-14010011' and sn=snandpcbsn.sn)
and pcbsn=caltest.pcbsn
)
)t
where rownum = 1