如何最优写这条SQL语句(附表结构)

RuimeiSoft 2005-07-08 11:23:16
第一个表Product表,字段有:ProductId ProductName ReleaseData
第二表ProductSKU表,字段有:ProductId SKU ReleaseDate
他们是一对多的关系
即一个Product可以有多个SKU,但至少有一个

现在要解决的问题是:
提取最新的10条含有至少2个SKU的Product信息
请问如何写这个SQL语句?
...全文
130 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
RuimeiSoft 2005-07-08
  • 打赏
  • 举报
回复
RuimeiSoft 2005-07-08
  • 打赏
  • 举报
回复
排序方式我要根据ProductSKU表的ReleaseData
JasonHeung 2005-07-08
  • 打赏
  • 举报
回复
xyy2(爱) ( ) 信誉:100 2005-07-08 11:52:00 得分: 0


select top 10 ProductId ,ProductName ,ReleaseData from Product
where ProductId in (
select ProductId from ProductSKU
group by ProductId
having count(SKU) >= 2
)
order by ReleaseData desc


xyy2 2005-07-08
  • 打赏
  • 举报
回复
select top 10 ProductId ,ProductName ,ReleaseData from Product
where ProductId in (
select ProductId from ProductSKU
group by ProductId
having count(SKU) >= 2
)
order by ReleaseData desc
xyy2 2005-07-08
  • 打赏
  • 举报
回复
select ProductId ,ProductName ,ReleaseData from Product
where ProductId in (
select ProductId from ProductSKU
group by ProductId
having count(SKU) >= 2
)
李洪喜 2005-07-08
  • 打赏
  • 举报
回复
select top 10 ProductId ,max( ReleaseDate) as dt ProductSKU
group by ProductId
having count(*)>=3
order by ReleaseDate

大体上是这样吧。
试一试吧。

spz1755 2005-07-08
  • 打赏
  • 举报
回复
想不出来,帮你顶吧
RuimeiSoft 2005-07-08
  • 打赏
  • 举报
回复
ding
RuimeiSoft 2005-07-08
  • 打赏
  • 举报
回复
SQL Server
spz1755 2005-07-08
  • 打赏
  • 举报
回复
是SQL Server还是Oracle?
syeerzy 2005-07-08
  • 打赏
  • 举报
回复
SELECT TOP 10 ProductId ,ProductName ,ReleaseData
FROM Product
WHERE ProductId IN
(
SELECT DISTINCT ProductId
FROM ProductSKU
GROUP BY ProductId
HAVING Count(SKU) > 1
)
ORDER BY ReleaseData DESC

111,125

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧