1.Using the following table:
Code CategoryName LastUpdated
1 Cloths 01.01.2007
1 Wear 01.01.2006
1 Wears 03.10.2005
2 Computers 03.04.2007
2 Hardware & Software 01.02.2006
3 Office equipment 03.10.2006Write SQL statement to get all current category names (without the old values).
看这张表里的有重复的Code,查询在重复的Code里取最新时间里的一条记录(如Code中有三个1,取其中时间最新的01.01.2007,两个2中取最新时间是03.04.2007),实现如下图,写一条SQL语句Code Category
1 Cloths
2 Computers
3 Office equipment
谢谢……
2. Using the following table:
Code CategoryName LastUpdated
1 Cloths 01.01.2007
2 Wear 01.01.2006
3 Wears 03.10.2005
4 Computers 03.04.2007
5 Hardware & Software 01.02.2006
6 Office equipment 03.10.2006写一个存储过程,如果输入1就查询出Cloths,如查输入2就查询出Wears,……谢谢大哥们哦!
Code CategoryName LastUpdated
1 Cloths 01.01.2007
1 Wear 01.01.2006
1 Wears 03.10.2005
2 Computers 03.04.2007
2 Hardware & Software 01.02.2006
3 Office equipment 03.10.2006Write SQL statement to get all current category names (without the old values).
看这张表里的有重复的Code,查询在重复的Code里取最新时间里的一条记录(如Code中有三个1,取其中时间最新的01.01.2007,两个2中取最新时间是03.04.2007),实现如下图,写一条SQL语句Code Category
1 Cloths
2 Computers
3 Office equipment
谢谢……
2. Using the following table:
Code CategoryName LastUpdated
1 Cloths 01.01.2007
2 Wear 01.01.2006
3 Wears 03.10.2005
4 Computers 03.04.2007
5 Hardware & Software 01.02.2006
6 Office equipment 03.10.2006写一个存储过程,如果输入1就查询出Cloths,如查输入2就查询出Wears,……谢谢大哥们哦!
select code,Category=CategoryName
from tb k
where not exists(select * from tb where k.code=code and DATEDIFF(day,LastUpdated,k.LastUpdated)<0)--no_2
create proc pro_search
@code int
as
select CategoryName
from tb
where code=@code