各位大牛问个查询产品表分类的有关问题
各位大牛问个查询产品表分类的问题
如何查询产品表Type字段不同的值的数据各查询10条?同时带一个产品名称的模糊查询。
------解决思路----------------------
吧你的需求贴上来。这样讲很难帮忙你解决
------解决思路----------------------
需求不明确啊
------解决思路----------------------
给个表结构或数据,以及你想要的结果,把问题表述明白
------解决思路----------------------
declare @A TABLE(type1 int,name varchar(2))
insert into @A
select 1,'a'
union
select 1,'b'
union
select 1,'c'
union
select 1,'d'
union
select 2,'b'
union
select 3,'b'
union
select 2,'d'
union
select 3,'d'
select ROW_NUMBER() over(partition by type1 order by type1),* from @A
order by type1,name
------解决思路----------------------
declare @A TABLE(type1 int,name varchar(2))
insert into @A
select 1,'a'
union
select 1,'b'
union
select 1,'c'
union
select 1,'d'
union
select 2,'b'
union
select 3,'b'
union
select 2,'d'
union
select 3,'d'
select * from (
select ROW_NUMBER() over(partition by type1 order by type1) id,* from @A
)t
where id<=10
------解决思路----------------------
如何查询产品表Type字段不同的值的数据各查询10条?同时带一个产品名称的模糊查询。
------解决思路----------------------
吧你的需求贴上来。这样讲很难帮忙你解决
------解决思路----------------------
需求不明确啊
------解决思路----------------------
给个表结构或数据,以及你想要的结果,把问题表述明白
------解决思路----------------------
declare @A TABLE(type1 int,name varchar(2))
insert into @A
select 1,'a'
union
select 1,'b'
union
select 1,'c'
union
select 1,'d'
union
select 2,'b'
union
select 3,'b'
union
select 2,'d'
union
select 3,'d'
select ROW_NUMBER() over(partition by type1 order by type1),* from @A
order by type1,name
------解决思路----------------------
declare @A TABLE(type1 int,name varchar(2))
insert into @A
select 1,'a'
union
select 1,'b'
union
select 1,'c'
union
select 1,'d'
union
select 2,'b'
union
select 3,'b'
union
select 2,'d'
union
select 3,'d'
select * from (
select ROW_NUMBER() over(partition by type1 order by type1) id,* from @A
)t
where id<=10
------解决思路----------------------
select a.*
from 产品表 AS a,
(
select id,rn=ROW_NUMBER() over(partition by [Type] order by ProductName)
from 产品表
where ProductName like '%香蕉%'
) AS b
where a.id=b.id and b.rn<=10