liuchunping454135329
2010-12-29 17:33
浏览 222

sql查询无奈!

查询所有设备最近一次备份历史记录,要求显示设备名称,文件名,最近备份时间,ip等。
SELECT DEVICEHISTORYID, NEDN, FILENAME, BACKTIME, BASELINEFLAG, RESULT, RUNDATE, TASKNAME, BACKTYPE
FROM DBSNMP.TBL_CONFMGR_DEVICEHISTORY(设备历史记录表)
SELECT NEDN, SYSNAME, NENAME, NECATEGORY, NETYPE, NEVENDORNAME, NEIP, NEMASK, NEMAC, VERSION, NEPATCHVERSION, NESYSOID, NEEXTENATTR, NESTATE, LASTPOLLTIME
FROM DBSNMP.TBL_NE_INFO(设备表)

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

4条回答 默认 最新

  • zgy52188 2010-12-30 08:50
    已采纳

    看你给的字段都不知道是表示什么的只能猜,麻烦。这里我当backtime是备份时间了。
    首先查询历史记录表以设备分组,因为设备标号只定唯一,查询最大备份时间,这样确定一个最大备份时间表,然后在和设备表一起查询就好办了。

    [code="sql"]
    select t.NENAME,c.FILENAME,c.BACKTIME,t.NEIP --别的字段自己加
    from DBSNMP.TBL_NE_INFO t,

    (SELECT DEVICEHISTORYID, NEDN as NEDN, FILENAME as FILENAME,BASELINEFLAG, RESULT, RUNDATE, TASKNAME, BACKTYPE,
    max(BACKTIME) as BACKTIME

    FROM DBSNMP.TBL_CONFMGR_DEVICEHISTORY

    group by NEDN) c

    where t.NEDN = c.NEDN [/code]

    打赏 评论
  • lang_shao 2010-12-29 17:57

    [code="sql"]
    -- NEDN 是设备的ID吗? 如果是,则:
    select t.*
    from DBSNMP.TBL_CONFMGR_DEVICEHISTORY t,
    (SELECT NEDN, -- 是设备的ID吗?
    max(BACKTIME) as BACKTIME -- 是备份时间吗?
    FROM DBSNMP.TBL_CONFMGR_DEVICEHISTORY
    group by NEDN) c
    where t.NEDN = c.NEDN
    and t.BACKTIME = c.BACKTIME
    [/code]

    打赏 评论
  • iteye_4873 2010-12-29 18:01

    [code="SQL"]
    select a.NENAME,b.FILENAME,b.RUNDATE,a.NEIP from DBSNMP.TBL_NE_INFO a,

    (
    select * from DBSNMP.TBL_CONFMGR_DEVICEHISTORY c,
    (select nedn,max(RUNDATE) from
    DBSNMP.TBL_CONFMGR_DEVICEHISTORY group by NEDN) d
    where c.nedn = d.nedn and c.rundate = d.rundate
    ) b
    where a.nedn = b.nedn
    [/code]

    试试~

    打赏 评论
  • iteye_4873 2010-12-30 09:23

    我发的那个SQL是把RUNDATE 当备份时间了~

    还有LS的SQL,这段确定能执行吗~ 明显有问题哦~
    [quote]SELECT DEVICEHISTORYID, NEDN as NEDN, FILENAME as FILENAME,BASELINEFLAG, RESULT, RUNDATE, TASKNAME, BACKTYPE,

    max(BACKTIME) as BACKTIME

    FROM DBSNMP.TBL_CONFMGR_DEVICEHISTORY

    group by NEDN[/quote]

    打赏 评论

相关推荐 更多相似问题