澳门美高梅游戏

澳门美高梅游戏官方网站 > 澳门美高梅游戏 > 批量插入数据,计算分页一些sql

原标题:批量插入数据,计算分页一些sql

浏览次数:113 时间:2019-10-04

转自:http://www.maomao365.com/?p=6873

mysql 的核心错误跳过和mariadb的多源主从复制错误跳过操作区别,请小心:
转移会话的default_master_connection变量

USE [QPTreasureDB]
GO
/****** Object: StoredProcedure [dbo].[GameStatistics] Script Date: 2018/8/16 10:33:10 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROC [dbo].[GameStatistics]
@Type INT,
@GameType INT,
@Year INT,
@Month INT,
@Day INT,
@PageIndex INT,
@PageSize INT
AS -- 属性设置
SET NOCOUNT ON;

-- 执行逻辑
BEGIN
IF (@Type = 0)
BEGIN
IF (@GameType = 2)
BEGIN
SELECT SUM(-lwinscore) AS TotalProfitAndLoss, --总盈亏
SUM(lalladdscore) AS PlayIn, --玩入
SUM(- (lwinscore + lalladdscore)) AS PlayOut --玩出
FROM [QPPlatformDB].[dbo].[FiveStarRecord]
WHERE YEAR(insertTime) = CASE @Year
WHEN -1 THEN YEAR(insertTime)
ELSE @Year END
AND MONTH(insertTime) = CASE @Month
WHEN -1 THEN MONTH(insertTime)
ELSE @Month END
AND DAY(insertTime) = CASE @Day
WHEN -1 THEN DAY(insertTime)
ELSE @Day END;
END;
IF (@GameType = 3)
BEGIN
SELECT YEAR(insertTime) Year,
SUM(-lwinscore) AS RichTotalProfitAndLoss, --总盈亏
SUM(lalladdscore) AS RichPlayIn, --玩入
SUM(- (lwinscore + lalladdscore)) AS RichPlayOut --玩出
FROM [QPPlatformDB].[dbo].[FiveStarRecord]
GROUP BY YEAR(insertTime);
END;
END;
ELSE IF (@Type = 1) --月统计
BEGIN
SELECT @Year Year,
MONTH(insertTime) Month,
SUM(-lwinscore) AS RichTotalProfitAndLoss, --总盈亏
SUM(lalladdscore) AS RichPlayIn, --玩入
SUM(- (lwinscore + lalladdscore)) AS RichPlayOut --玩出
FROM [QPPlatformDB].[dbo].[FiveStarRecord]
WHERE YEAR(insertTime) = @Year
GROUP BY MONTH(insertTime);
END;
ELSE IF (@Type = 2) --日统计
BEGIN
SELECT @Year Year,
@Month Month,
DAY(insertTime) Day,
SUM(-lwinscore) AS RichTotalProfitAndLoss, --总盈亏
SUM(lalladdscore) AS RichPlayIn, --玩入
SUM(- (lwinscore + lalladdscore)) AS RichPlayOut --玩出
FROM [QPPlatformDB].[dbo].[FiveStarRecord]
WHERE YEAR(insertTime) = @Year
AND MONTH(insertTime) = @Month
GROUP BY DAY(insertTime);
END;
ELSE IF (@Type = 3) --日统计
BEGIN
DECLARE @RecordCount INT;
SELECT @RecordCount = COUNT(*)
FROM [QPPlatformDB].[dbo].[FiveStarRecord]
WHERE YEAR(insertTime) = @Year
AND MONTH(insertTime) = @Month
AND DAY(insertTime) = @Day
GROUP BY dwUserID,
lwinscore,
lalladdscore,
lAreaScore1,
lAreaScore2,
lAreaScore3,
lAreaScore4,
lAreaScore5,
insertTime;
DECLARE @TotalProfitAndLoss VARCHAR(255)
DECLARE @TotalPlayIn VARCHAR(255)
DECLARE @TotalPlayOut VARCHAR(255)
DECLARE @PageCount INT

SELECT 
@PageCount=COUNT(dwUserID),
@TotalProfitAndLoss=SUM(-lwinscore), --总盈亏
@TotalPlayIn=SUM(lalladdscore), --玩入
@TotalPlayOut=SUM(- (lwinscore + lalladdscore)) --玩出
FROM [QPPlatformDB].[dbo].[FiveStarRecord]
WHERE YEAR(insertTime) = @Year
AND MONTH(insertTime) = @Month
AND DAY(insertTime) = @Day;
DECLARE @StartIndex INT ,
@EndIndex INT
SELECT @StartIndex = ( @PageIndex - 1 ) * @PageSize + 1 ,
@EndIndex = @PageIndex * @PageSize;
WITH Pager
AS ( SELECT ROW_NUMBER() OVER (ORDER BY dwUserID ASC) AS Id,
dwUserID,
@PageCount PageCount,
@TotalProfitAndLoss AS TotalProfitAndLoss, --总盈亏
@TotalPlayIn AS TotalPlayIn, --玩入
@TotalPlayOut AS TotalPlayOut, --玩出
-lwinscore AS RichProfitAndLoss, --总盈亏
lalladdscore AS RichPlayIn, --玩入
- (lwinscore + lalladdscore) AS RichPlayOut, --玩出
lAreaScore1,
lAreaScore2,
lAreaScore3,
lAreaScore4,
lAreaScore5,
insertTime
FROM [QPPlatformDB].[dbo].[FiveStarRecord]
WHERE YEAR(insertTime) = @Year
AND MONTH(insertTime) = @Month
AND DAY(insertTime) = @Day
GROUP BY dwUserID,
lwinscore,
lalladdscore,
lAreaScore1,
lAreaScore2,
lAreaScore3,
lAreaScore4,
lAreaScore5,
insertTime)
SELECT *
FROM Pager
WHERE Id BETWEEN @StartIndex AND @EndIndex

END;
END;
Create proc setup_list_add
@creatime  Datetime--创建时间
,@objjc Varchar(20)--排期项目
,@Doctor Varchar(20)--接诊医生
,@beginDate Datetime--排班开始
,@endtDate Datetime--排班结束
,@objuser Varchar(20)--排班人
as
begin
begin transaction T1
Declare @n Datetime
set @n=@beginDate
while @n<=@endtDate
begin

 insert into Scheduling_setup(creatime,objjc,Doctor,begintime,endtime,objuser) 
 select @creatime,@objjc,@Doctor,CONVERT(char(16), @n+begintime,120),endtime,@objuser from times_setup where objjc=@objjc
set @n=dateadd(dd,1,@n)
end

IF @@ERROR <> 0 GOTO FINALROLL
 select '添加成功!' msg,1 code
COMMIT TRAN T1
RETURN

FINALROLL:
    select '添加失败'  msg,2 code
ROLLBACK TRAN T1
end
Go
  1. innodb 行锁是依照索引实现的,假若不通过索引访问数据,innodb会动用表锁。

摘要:
下文通过案例解析in 关键字在值为null的行使举例,
剖析出not in关键字在null值产生的丰裕消息
平日来讲所示:

STOP SLAVE 'slave_account';
SET @@default_master_connection = 'slave_account';
SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1;
START SLAVE 'slave_account';
SET @@default_master_connection = '';

 

 

   批量插入数据,计算分页一些sql。  http://www.cnblogs.com/MrHSR/p/9376086.html

CREATE TABLE testA(keyId INT)
CREATE TABLE testB(keyId INT)
GO
INSERT INTO testA(keyId) VALUES (1)
INSERT INTO testA(keyId) VALUES (2)
INSERT INTO testA(keyId) VALUES (3)
GO
INSERT INTO testB(keyId) VALUES (1)
INSERT INTO testB(keyId) VALUES (2)
INSERT INTO testB(keyId) VALUES (4)
INSERT INTO testB(keyId) VALUES (NULL)
GO
 SELECT * FROM testA WHERE keyId IN (SELECT keyId FROM testB)
-----输出------
/*
keyId
1
2
*/
 SELECT * FROM testA WHERE keyId not IN (SELECT keyId FROM testB)
------无输出记录-----
/*
keyId
*/
INSERT INTO testA VALUES (NULL) ---在testA表中插入空值
SELECT * FROM testA WHERE EXISTS(
    SELECT null  FROM testB WHERE testA.keyId=testB.keyId    
)
----输出----
/*
keyId
1
2
*/
SELECT * FROM testA WHERE not  EXISTS(
    SELECT null  FROM testB WHERE testA.keyId=testB.keyId    
)
/*
keyId
3
NULL
*/
SELECT * FROM testA WHERE testA.keyId NOT in (
    SELECT testB.keyId FROM testB WHERE testB.keyId IS NOT NULL    
)

drop table testA
drop table testB

 2. Innodb 空隙锁(Next-key)机制,以及innodb使用间隙锁的来由

本文由澳门美高梅游戏官方网站发布于澳门美高梅游戏,转载请注明出处:批量插入数据,计算分页一些sql

关键词:

上一篇:没有了

下一篇:没有了