求一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'的记录。
...全文
122 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
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
  • 打赏
  • 举报
回复
哎,算了,揭帖.

34,587

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧