• 获取数据的时候减少重复值


    我们如果从一张表中获取数据的时候,可能会有重复的情况,那么我们如何去重操作,我这里是用一张表获取最大id值来控制的。

     在查询数据之前先获取最大的id值是多少,然后将id值传过去,作为查询条件之后,将最后一条id值作为最大id值进行保存,在下一次进行查询时使用。

    sql文件

    -- ----------------------------
    -- Table structure for maxidsave
    -- ----------------------------
    DROP TABLE [dbo].[maxidsave]
    GO
    CREATE TABLE [dbo].[maxidsave] (
    [id] int NOT NULL IDENTITY(1,1) ,
    [name] varchar(50) NULL ,
    [tablename] varchar(50) NULL ,
    [maxid] int NULL 
    )
    
    
    GO
    DBCC CHECKIDENT(N'[dbo].[maxidsave]', RESEED, 4)
    GO
    IF ((SELECT COUNT(*) from fn_listextendedproperty('MS_Description', 
    'SCHEMA', N'dbo', 
    'TABLE', N'maxidsave', 
    NULL, NULL)) > 0) 
    EXEC sp_updateextendedproperty @name = N'MS_Description', @value = N'记录最大ID数、名称、表名'
    , @level0type = 'SCHEMA', @level0name = N'dbo'
    , @level1type = 'TABLE', @level1name = N'maxidsave'
    ELSE
    EXEC sp_addextendedproperty @name = N'MS_Description', @value = N'记录最大ID数、名称、表名'
    , @level0type = 'SCHEMA', @level0name = N'dbo'
    , @level1type = 'TABLE', @level1name = N'maxidsave'
    GO
    IF ((SELECT COUNT(*) from fn_listextendedproperty('MS_Description', 
    'SCHEMA', N'dbo', 
    'TABLE', N'maxidsave', 
    'COLUMN', N'name')) > 0) 
    EXEC sp_updateextendedproperty @name = N'MS_Description', @value = N'名称、方法名、接口名等'
    , @level0type = 'SCHEMA', @level0name = N'dbo'
    , @level1type = 'TABLE', @level1name = N'maxidsave'
    , @level2type = 'COLUMN', @level2name = N'name'
    ELSE
    EXEC sp_addextendedproperty @name = N'MS_Description', @value = N'名称、方法名、接口名等'
    , @level0type = 'SCHEMA', @level0name = N'dbo'
    , @level1type = 'TABLE', @level1name = N'maxidsave'
    , @level2type = 'COLUMN', @level2name = N'name'
    GO
    IF ((SELECT COUNT(*) from fn_listextendedproperty('MS_Description', 
    'SCHEMA', N'dbo', 
    'TABLE', N'maxidsave', 
    'COLUMN', N'tablename')) > 0) 
    EXEC sp_updateextendedproperty @name = N'MS_Description', @value = N'表名'
    , @level0type = 'SCHEMA', @level0name = N'dbo'
    , @level1type = 'TABLE', @level1name = N'maxidsave'
    , @level2type = 'COLUMN', @level2name = N'tablename'
    ELSE
    EXEC sp_addextendedproperty @name = N'MS_Description', @value = N'表名'
    , @level0type = 'SCHEMA', @level0name = N'dbo'
    , @level1type = 'TABLE', @level1name = N'maxidsave'
    , @level2type = 'COLUMN', @level2name = N'tablename'
    GO
    IF ((SELECT COUNT(*) from fn_listextendedproperty('MS_Description', 
    'SCHEMA', N'dbo', 
    'TABLE', N'maxidsave', 
    'COLUMN', N'maxid')) > 0) 
    EXEC sp_updateextendedproperty @name = N'MS_Description', @value = N'最大ID数'
    , @level0type = 'SCHEMA', @level0name = N'dbo'
    , @level1type = 'TABLE', @level1name = N'maxidsave'
    , @level2type = 'COLUMN', @level2name = N'maxid'
    ELSE
    EXEC sp_addextendedproperty @name = N'MS_Description', @value = N'最大ID数'
    , @level0type = 'SCHEMA', @level0name = N'dbo'
    , @level1type = 'TABLE', @level1name = N'maxidsave'
    , @level2type = 'COLUMN', @level2name = N'maxid'
    GO
    
    -- ----------------------------
    -- Indexes structure for table maxidsave
    -- ----------------------------
    
    -- ----------------------------
    -- Primary Key structure for table maxidsave
    -- ----------------------------
    ALTER TABLE [dbo].[maxidsave] ADD PRIMARY KEY ([id])
    GO
  • 相关阅读:
    LightOJ 1313
    LightOJ 1285
    [坑] treap
    HDU 4511 小明系列故事——女友的考验 (AC自动机+DP)
    ZOJ 3765 Lights (伸展树splay)
    HDU 4818 RP problem (高斯消元, 2013年长春区域赛F题)
    SGU 104. Little shop of flowers (DP)
    HDU 3472 HS BDC (混合图的欧拉路径判断)
    POJ 1386 Play on Words (有向图欧拉路径判定)
    微信小程序上架需要增值电信业务经营许可证ICP?
  • 原文地址:https://www.cnblogs.com/q1359720840/p/10487524.html
Copyright © 2020-2023  润新知