求助一个存储过程,烦请帮帮忙,十分感谢!
文章(Article)表和标签(Tag)表是多对多关系
用一个ActicleTag的中间表联接,该表中有aId和tId联合构成的主键, 两边的一对多关系已经设好
请问如何选出 拥有文章数最多的前10个标签
请高手帮帮忙,给个最佳实践好吗?谢谢!!!
------解决方案--------------------没看到表不知道怎么回事
------解决方案--------------------得有具体的表,才能分析.
我这有个寻求父子关系的存储过程,希望能给你点借鉴.
CREATE PROC up_GetTeamMen
@LeaderId int
AS
CREATE TABLE #TeamMen (EmployeeID int PRIMARY KEY, FirstName varchar(20) NOT NULL,SupervisorID int)
INSERT INTO #TeamMen SELECT EmployeeID,FirstName,SupervisorID FROM Employees WHERE SupervisorID=@LeaderId
WHILE EXISTS(SELECT EmployeeID,FirstName,SupervisorID FROM Employees WHERE
SupervisorID IN (SELECT EmployeeID FROM #TeamMen) AND
EmployeeID NOT IN (SELECT EmployeeID FROM #TeamMen))
BEGIN
INSERT INTO #TeamMen SELECT EmployeeID,FirstName,SupervisorID FROM Employees WHERE
SupervisorID IN (SELECT EmployeeID FROM #TeamMen) AND
EmployeeID NOT IN (SELECT EmployeeID FROM #TeamMen)
END
SELECT * FROM #TeamMen
GO