zoukankan      html  css  js  c++  java
  • MSSQL

    USE [DB_News]
    GO
    /****** Object:  StoredProcedure [dbo].[SelectHotNews]    Script Date: 2015/7/8 13:34:46 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    -- =============================================
    -- Author:		HF_Ultrastrong
    -- Create date: 2015年7月5日16:40:20
    -- Description:	取出10条热点新闻 (热点新闻:评论最多)
    -- =============================================
    ALTER PROCEDURE [dbo].[SelectHotNews]
    AS
    BEGIN
    	select top 5 n.ID, n.Title, n.CreateTime, c.Name, count(t.ID) as CountNumber
    	from Tb_News as n
    	inner join Tb_Category as c on n.CaId = c.ID
    	--用左连接,这样可以查询出评论为0的新闻
    	left join Tb_Comment as t on t.NewsId = n.ID
    	group by n.ID, n.Title, n.CreateTime, c.Name
    	order by CountNumber desc
    END
    

    其中涉及到三张表,分类表,新闻表,评论表。

    最终取出效果:

  • 相关阅读:
    购物车案例详解。利用cookie
    设计模式8种
    设计模式介绍
    Promise
    面向对象-拖拽
    本地存储
    闭包和继承
    move.js
    CDM指南之Agent管理
    失业的程序员九创业就是一场戏
  • 原文地址:https://www.cnblogs.com/KTblog/p/4629931.html
Copyright © 2011-2022 走看看