数据库表A 有个字段a是int类型
a中有数据有1到9任意(有重复的)
想取得a中,当 a=1时 a=2时 a=3…… 各一条记录的列表
能用sql搞定吗 要考虑效率
更正
select top 1 * from A where a=1
union
select top 1 * from A where a=2
...
union
select top 1 * from A where a=9
select a,sum(b) 或min(b)或max(b) from A group by a
用分组显示.不知道对其它字段显示是什么要求
增加个字段,自曾的,再用分组
select distinct a,字段名1 from A
[quote]select a,sum(b) 或min(b)或max(b) from A group by a
用分组显示.不知道对其它字段显示是什么要求[/quote]
如果就2个字段呢? 那id 不是就乱了?
select top 1 * from A where a=1
union
select top 2 * from A where a=2
...
union
select top 2 * from A where a=9
我估计要么在a字段上建有索引,要么就是记录数少,否则再怎么写查询语句性能都不会高。