导航
  • 主页
  • 基础类
  • 应用实例
  • 新技术前沿

求一SELECT语句!!!

seahi 2007-12-25 10:46:11
select * from a
left join b on a.xxx=b.xxx
where b.aaa is null or b.aaa<='xxxx'

以上语句中表A和表B中均没有主键,使用该语句会查出多条符合条件的语句。
我希望达到的效果是当b.aaa is null有满足条件的记录时便不再查询出符合条件b.aaa<='xxxx'的记录
只有当b.aaa is null没有满足条件的记录的时候才查询满足条件b.aaa<='xxxx'的记录。
...全文
88 点赞 收藏 12
写回复
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
seahi 2007-12-25
再问个小儿科问题

ALTER FUNCTION udf_shop_employees_lastshop()
RETURNS @shop_employees_lastshop TABLE
(
emp_id char(10) NOT NULL
)
AS
BEGIN
INSERT @shop_employees_lastshop
select emp_id from shop_employees

RETURN;
END
GO

提示错误信息:
Msg 2010, Level 16, State 1, Procedure udf_shop_employees_lastshop, Line 17
Cannot perform alter on 'udf_shop_employees_lastshop' because it is an incompatible object type.
是何意思啊?自定义函数写的少,没有经验啊.谢啦.
回复
seahi 2007-12-25
看来这个问题不好解决,写自定义函数应该会比较容易点吧!?
回复
wzy_love_sly 2007-12-25
楼主好猛..................
回复
seahi 2007-12-25
1楼的查出的结果和我那句没区别,2-4楼更不用说,达不到我的要求,5楼错误,如果bbb不为null则扫描记录也找不出来.
7楼结果虽然对,但由于我的这个语句是嵌套在SELECT语句中的,所以还是不能用,请大家再想想!
回复
wzy_love_sly 2007-12-25
if exists(select 1 from a left join b on a.xxx=b.xxx whereb.aaa is null)
select * from a left join b on a.xxx=b.xxx whereb.aaa is null
else
select * from a left join b on a.xxx=b.xxx where b.aaa <='xxxx'
回复
areswang 2007-12-25
应该是楼上的。
回复
-狙击手- 2007-12-25
select   *   from   a 
right join b on a.xxx=b.xxx and b.aaa is null
where b.aaa <='xxxx'
回复
wzy_love_sly 2007-12-25
select * from a
left join b on a.xxx=b.xxx
where b.aaa is null

union

select * from a
left join b on a.xxx=b.xxx
where b.aaa is not null and b.aaa <='xxxx'

回复
areswang 2007-12-25
select * from a
left join b on a.xxx=b.xxx
where b.aaa is null
union all
select * from a
left join b on a.xxx=b.xxx
where b.aaa <='xxxx'
回复
wzy_love_sly 2007-12-25
select * from a
left join b on a.xxx=b.xxx
where b.aaa is null

union

select * from a
left join b on a.xxx=b.xxx
where b.aaa is null and b.aaa<='xxxx'

再想想
回复
playwarcraft 2007-12-25
where b.aaa is null
or (b.aaa is not null and b.aaa <='xxxx' )
回复
seahi 2007-12-25
哎,算了,揭帖.
回复
发动态
发帖子
MS-SQL Server
创建于2007-09-28

3.2w+

社区成员

MS-SQL Server相关内容讨论专区
申请成为版主
社区公告
暂无公告