select b.aid,a.name,b.status from a inner join b on a.aid=b.aid
where b.status=3
解决方案 »
- 天哪,为什么会出现[object Window]?
- 关于 edit and contiue(sos)
- GridView不显示的问题
- 如何在asp.net中删除缓存信息啊?
- 哪位有书 ASP_NET.XML高级编程-C#编程篇 的源码
- 为何REPEATER取不到TEXTBOX中的值。
- 用C#在ASP.NET里边怎样更改EXCEL的SHEET名(假设只有一个SHEET)
- 用户控件问题
- ASP和ASP.net的服务器配置有何不同?只需要IIS5.0就可使用ASP.net吗?
- 按钮函数不响应按钮事件的问题
- 要实现这个逻辑图,我要了解一些什么知识啊。请大神们给个方向...
- 用gridview排班,大神们帮一下忙阿。。
select
A.aid,A.name,B.status
from
A
left join
B on A.aid=B.aid
where
B.status=3
select a.aid,a.name,b.status from a
join b
on a.aid=b.aid
where b.status=3
B表
aid status
10 3
10 3
如果有两个status=3的时候 那你两个都查出来了 我只要最后一个数据
aid status
10 3
10 3
如果有两个status=3的时候 那你两个都查出来了 我只要最后一个数据
aid status
10 3
10 3
如果有两个status=3的时候 那你两个都查出来了 我只要最后一个数据
aid status
10 3
10 3
如果有两个status=3的时候 那你两个都查出来了 我只要最后一个数据你就不能查出来后再程序里再做处理的。非要把所有事情都压在数据库上啊
况且按你的描述“插入了多个aid的记录,staus状态不同”哪可能存在同一个aid对应两个相通的status啊
aid,name (aid唯一)
10 sel
表2 B
bid,aid,status(插入了多个aid的记录)
1 10 1
2 10 2
3 10 3
4 10 2
5 10 3
A关联查询B的最后一条数据,并可进行status条件查询(where B.status=3)
结果
aid name status
10 sel 3
aid status
10 3
10 3
如果有两个status=3的时候 那你两个都查出来了 我只要最后一个数据你就不能查出来后再程序里再做处理的。非要把所有事情都压在数据库上啊
况且按你的描述“插入了多个aid的记录,staus状态不同”哪可能存在同一个aid对应两个相通的status啊表1 A
aid,name (aid唯一)
10 sel
表2 B
bid,aid,status(插入了多个aid的记录)
1 10 1
2 10 2
3 10 3
4 10 2
5 10 3
A关联查询B的最后一条数据,并可进行status条件查询(where B.status=3)
结果
aid name status
10 sel 3
select a.aid,a.name,b.status from A
where (select Max(bid) from B where A.aid=B.bid and.status=3) is not null
select
A.aid,A.name,B.status
from
A
left join
(select max(bid) bid,aid,status from B group by aid,status)B on A.aid=B.aid
where
B.status=3
id int,
name varchar(50)
)
insert into #a(id,name) values(10,'aa')
insert into #a(id,name) values(11,'bb')
insert into #a(id,name) values(12,'cc')
insert into #a(id,name) values(13,'dd')create table #b(
id int,
statuss int
)
insert into #b(id,statuss) values(10,3)
insert into #b(id,statuss) values(11,4)
insert into #b(id,statuss) values(11,3)
insert into #b(id,statuss) values(10,5)--#b表 statuss 最大值select MAX(statuss) statuss,id into #c from #b group by id
select a.name, c.id,c.statuss from #a a inner join #c c on
a.id=c.id
--where b.statuss=3
drop table #a
drop table #b
drop table #c
top 1 A.aid,A.name,B.status
from
A
left join
B on A.aid=B.aid
where
B.status=3
order by
B.bid desc
这是思路
aid,status(插入了多个aid的记录,staus状态不同)
10 1
10 2
10 3
我怎么知道哪个是最后一条记录?以什么方式进行排序?
Select aid,[name],(select top 1 [status] From B Where A.aid=B.aid Order by [status] DESC) as status
From A
) Where status=3