求数据查询方法,t-sql、linq to sql不限

hb1122 2010-06-22 11:18:09
表A:
fields:
url nvarchar
status nvarchar //值为:更新中;己更新

表A数据
url,status
12521/52362.jpg,'更新中'
12521/52362.jpg,'己更新'
12522/55333.jpg,'更新中'
12523/55334.jpg,'更新中'
12523/55334.jpg,'己更新'

表B:
fields:
url nvarchar

表B数据
url
12521/52362.jpg
12522/55333.jpg


查询目地:查找表A所有status为'己更新'和表A中所有在表B存在的url,查询结果url为唯一
...全文
129 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
liuyang509 2010-06-23
  • 打赏
  • 举报
回复
路过 学习了
浪子-无悔 2010-06-23
  • 打赏
  • 举报
回复
楼上的可以实现 你的功能!
jiangshun 2010-06-23
  • 打赏
  • 举报
回复


--> 测试数据:[TA]
if object_id('[TA]') is not null drop table [TA]
create table [TA]([url] varchar(15),[status] varchar(6))
insert [TA]
select '12521/52362.jpg','更新中' union all
select '12521/52362.jpg','己更新' union all
select '12522/55333.jpg','更新中' union all
select '12523/55334.jpg','更新中' union all
select '12523/55334.jpg','己更新'
--> 测试数据:[TB:]
if object_id('[TB]') is not null drop table [TB]
create table [TB]([url] varchar(15))
insert [TB]
select '12521/52362.jpg' union all
select '12522/55333.jpg'

select * from [TA] A
where exists(select * from [TB] where A.url=url)
and status='更新中'.

/*
url status
--------------- ------
12521/52362.jpg 更新中
12522/55333.jpg 更新中

(2 行受影响)

*/

drop table [TA]
drop table [TB]
claymore1114 2010-06-23
  • 打赏
  • 举报
回复
select A.* from A where A.status='己更新' or exists(select url from B where url=A.url and status=A.status)
shiyuyao1987 2010-06-23
  • 打赏
  • 举报
回复
select * from A where status='己更新'
and exists(select 1 from B where B.url=A.url)
hb1122 2010-06-23
  • 打赏
  • 举报
回复
唉,测试了一下,无法取出正确的数据

1、表A中status为'己更新'的数据
2、表A中所有在表B中出现的数据(包括表A中status为'更新中'的数据)
hb1122 2010-06-23
  • 打赏
  • 举报
回复
突然发觉偶好小白
好后悔!
兔子-顾问 2010-06-23
  • 打赏
  • 举报
回复
问sql语句?咋不到sql版块问啊。我不懂sql。大概意思这样?如果能让查询分析器通过编译的话。。。
select * from A where status = '已更新' and A.url in select distinct(url) from B
hb1122 2010-06-22
  • 打赏
  • 举报
回复
多谢指点,学海无涯!
wuyq11 2010-06-22
  • 打赏
  • 举报
回复
select distinct url
xray2005 2010-06-22
  • 打赏
  • 举报
回复
如果有重新的URL,只想取一个URL那么,

select distinct(A.url)
from A
where A.url in (select url from B ) and A.status='己更新'
xray2005 2010-06-22
  • 打赏
  • 举报
回复
select A.*
from A
where A.url in (select url from B ) and A.status='己更新'

110,499

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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