linq查询 查询表中一个字段的数量,并返回前十个,使用count和top!
1个回答
展开全部
你问问题最好把表结构发出来,这样也节约你的时间。
=================================================
应该类似如下Linq
(
from c in 收藏表上下文
group c by c.产品ID into g
orderby g.Count() descending
select new
{
A=g.Key,
B=g.Count()
}
).Take(10)
------------
sql
SELECT TOP (10) [t1].[产品ID] AS [A], [t1].[value] AS [B]
FROM (
SELECT COUNT(*) AS [value],[t0].[产品ID]
FROM [收藏表] AS [t0]
GROUP BY [t0].[产品ID]
) AS [t1]
ORDER BY [t1].[value] DESC
=================================================
应该类似如下Linq
(
from c in 收藏表上下文
group c by c.产品ID into g
orderby g.Count() descending
select new
{
A=g.Key,
B=g.Count()
}
).Take(10)
------------
sql
SELECT TOP (10) [t1].[产品ID] AS [A], [t1].[value] AS [B]
FROM (
SELECT COUNT(*) AS [value],[t0].[产品ID]
FROM [收藏表] AS [t0]
GROUP BY [t0].[产品ID]
) AS [t1]
ORDER BY [t1].[value] DESC
追问
表结构是:收藏用户UserID,收藏产品ProductID!
追答
那一个userid可以多次收藏一种产品么?
是否会出现如下数据
userID ProductID
A P101
A P101
A P101
B P102
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询