表中有这样的数据:
1 0001 2005-05-05
2 0002 2005-05-05
3 0003 2005-05-05
4 0004 2005-05-05现在我只想查询出这样的数据集:
1 0001 2005-05-05
2 0002
3 0003
4 0004 这样的sql语句如何写呀?
谢谢各位大虾了
1 0001 2005-05-05
2 0002 2005-05-05
3 0003 2005-05-05
4 0004 2005-05-05现在我只想查询出这样的数据集:
1 0001 2005-05-05
2 0002
3 0003
4 0004 这样的sql语句如何写呀?
谢谢各位大虾了
1 0001 2005-05-05
select a.col1, a.col2, a.col3
from tbl as a left outer jion (select min(col1),col3 from tbl group by col3) as b
on a.col3=b.col3
union
select id,field1,null from table1 where id not in(
select min(id) from table1 group by field2)由于lz描述得太不清晰,所以只能随便写写
另外,也有兴趣知道要得到这样的数据集目的是什么,如果只是为了展现的话完全可以在UI层做一些简单处理而不是在sql里大费周章
from tbl as a left outer jion (select min(col1),col3 from tbl group by col3) as b
on a.col1=b.col1写错了,改下
on a.col3=b.col3
===>
on a.col1=b.col1
Select
ID,
Number,
(Case When Exists (Select * From TableName Where ID<A.ID And 日期=A.日期) Then '' Else 日期 End)
From TableName A