select * from table where category=6
只显示category为6的数据
select * from table limit 0,1
只显示
1 1001select * from table limit 2,1
只显示
1 2048select * from table GROUP BY category
只显示
1 1001
5 5895
8 2684
9 7896
只显示category为6的数据
select * from table limit 0,1
只显示
1 1001select * from table limit 2,1
只显示
1 2048select * from table GROUP BY category
只显示
1 1001
5 5895
8 2684
9 7896
FROM [table]
GROUP BY category这样好像不行吧。我以前做个,但是现在没有找到。
select * from table a where( category in(select top 1 * from table b where b.category=a.category))
category model
_____________________________________
1 1001
1 1358
1 2048
5 5895
5 6589
8 2684
8 6485
9 7896
-------------------------------------
现在我想求出它们中的category唯一的一行数据
就象distinct on (category)一样,但在MYSQL中没有
category model
-------------------------------------
1 1001
5 5895
8 2684
9 7896
-------------------------------------
只要得到唯一的一行数据就行了,有什么语句在MYSQL和PostgreSQL中同时实现呢?
不用程序代码控制,要纯的SQL实现。可以实现吗?select category,min(model) as model from tablename group by category
or
select category,max(model) as model from tablename group by category
select category,min(model) as model from tablename group by category
or
select category,max(model) as model from tablename group by category这倒是个好主意,不知道MYSQL中有没有MIN()函数,我先试一下。