zoukankan      html  css  js  c++  java
  • SQL 分组获取产品 前两条记录

    select * from
    (
    select *, ROW_NUMBER() over(partition by IPAddress order by recordtime desc) as rowNum
    from MonitoringSystem
    ) A
    where A.rowNum <= 1
    order by A.IPAddress, A.recordtime desc

    如果表中的数据是以秒记录的  但是显示的时候想以分钟显示 怎么办

     select * from MonitoringSystem
         where RecordTime in
           (
            select  MAX(RecordTime) from MonitoringSystem
            where IPAddress=@IPAddress
            group by convert(varchar(16),RecordTime,120) 
            )
        and RecordTime<=@CurrentTime 
        and RecordTime>=@PreTime
        and IPAddress=@IPAddress
        order by RecordTime asc

    原表结构

    USE [SimCloudV3.1]
    GO
    
    /****** Object:  Table [dbo].[MonitoringSystem]    Script Date: 12/06/2013 17:36:58 ******/
    SET ANSI_NULLS ON
    GO
    
    SET QUOTED_IDENTIFIER ON
    GO
    
    CREATE TABLE [dbo].[MonitoringSystem](
        [ID] [nvarchar](50) NULL,
        [CPU] [nvarchar](50) NULL,
        [AvailableMemory] [nvarchar](50) NULL,
        [TotalMemory] [nvarchar](50) NULL,
        [RecordTime] [datetime] NULL,
        [AddTime] [datetime] NULL,
        [ChangeTime] [datetime] NULL,
        [DNSName] [nvarchar](50) NULL,
        [IPAddress] [nvarchar](50) NULL,
        [NetWork] [nvarchar](50) NULL,
        [SummaryState] [nvarchar](50) NULL
    ) ON [PRIMARY]
    
    GO
  • 相关阅读:
    fastapi教程进阶
    fastapi快速入门
    Linux yum安装PostgreSQL9.6
    harbor helm仓库使用
    Dockfile文件解析
    K8S概念理解
    转载---Beats:如何使用Filebeat将MySQL日志发送到Elasticsearch
    Elasticsearch中text与keyword的区别
    filebeat知识点
    logstash知识点
  • 原文地址:https://www.cnblogs.com/ahghy/p/3461878.html
Copyright © 2011-2022 走看看