RICHEER COCA 2022-05-29 15:45 采纳率: 93.9%
浏览 26
已结题

请问如何开20个线程 执行以下这个SQL脚本?

SQL SERVER 2019的A_CENTER数据库里有个表QY_FRID_K10
请问如何开20个线程 执行以下这个SQL脚本?


DECLARE @times INT = 0; 
DECLARE @GroupID INT = 1;
DECLARE @Result TABLE(GroupId INT,WID INT, KID VARCHAR(5))
 
Start:
    DROP TABLE IF EXISTS #Result;
    DECLARE @Top10To15 INT=RAND()*3+12

    SELECT TOP(@Top10To15) WID,QY_RID,WValue,WNO,QY_FAID,TWO_ALL,SIX_ALL,XieLian,YanXu,BzwBALL,BuQue,DanQI,F_NOO
    INTO #Result 
    FROM [A_CENTER]..[QY_FRID_K10] WHERE WValue BETWEEN 2 AND 8 ORDER BY NEWID()

    INSERT #Result ( WID,QY_RID,WValue,WNO,QY_FAID,TWO_ALL,SIX_ALL,XieLian,YanXu,BzwBALL,BuQue,DanQI,F_NOO)
    SELECT  TOP (20 - @Top10To15)  WID,QY_RID,WValue,WNO,QY_FAID,TWO_ALL,SIX_ALL,XieLian,YanXu,BzwBALL,BuQue,DanQI,F_NOO FROM [A_CENTER]..[QY_FRID_K10] WHERE WValue NOT BETWEEN 2 AND 8 ORDER BY NEWID();
 
        IF EXISTS (   SELECT    1
                  FROM      #Result
                  HAVING    SUM(CASE WHEN QY_RID = 'A1' THEN 1 ELSE 0 END) BETWEEN 10 AND 10
                            AND SUM(CASE WHEN QY_RID = 'B1' THEN 1 ELSE 0 END) BETWEEN 5 AND 5
                            AND SUM(CASE WHEN QY_RID = 'C1' THEN 1 ELSE 0 END) BETWEEN 5 AND 5

                            AND SUM(CASE WHEN QY_FAID = 'F1' THEN 1 ELSE 0 END) BETWEEN 8 AND 8
                            AND SUM(CASE WHEN QY_FAID = 'S1' THEN 1 ELSE 0 END) BETWEEN 5 AND 5
                            AND SUM(CASE WHEN QY_FAID = 'T1' THEN 1 ELSE 0 END) BETWEEN 2 AND 2
                            AND SUM(CASE WHEN QY_FAID = 'L1' THEN 1 ELSE 0 END) BETWEEN 5 AND 5                            
                            )     
        BEGIN
            INSERT @Result (GroupId, WID, KID)        
            SELECT @GroupID, WID, 'N' + CAST(ROW_NUMBER() OVER (ORDER BY WID) AS VARCHAR(5)) AS KID FROM  #Result;
            SET @GroupID=@GroupID+1;
            IF @GroupID>5
                BEGIN
                INSERT INTO [WIN28b]..[Result_WIN28b]  --  SELECT * FROM [WIN28b]..[Result_WIN28b];
                    SELECT *   FROM  @Result PIVOT (MIN(WID) FOR KID IN (N1,N2,N3,N4,N5,N6,N7,N8,N9,N10,N11,N12,N13,N14,N15,N16,N17,N18,N19,N20)) p
                    RETURN
                END
            ELSE
                GOTO Start;
        END;
    ELSE
        GOTO Start;
  • 写回答

1条回答 默认 最新

  • 笑看风云路 大数据领域优质创作者 2022-05-31 08:15
    关注

    可以使用java创建多线程,连接MySQL数据库,去执行你的SQL语句!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 9月19日
  • 已采纳回答 9月11日
  • 创建了问题 5月29日

悬赏问题

  • ¥20 求有缘人帮我把笛卡尔坐标系转换为经纬度 有偿
  • ¥15 vue2中使用计算属性
  • ¥50 远程桌面打开Mastercam、没有许可证、物理机打开正常
  • ¥15 ubuntu安装gdal后java读取tif文件报错
  • ¥15 请问lammps怎么做两种金属连接的原子浓度分布图
  • ¥15 求jacquard数据集
  • ¥15 w10部分软件不能联网
  • ¥15 关于安装hbase的问题(操作系统-windows)
  • ¥15 novnc连接pve虚拟机报错安全协议不支持262
  • ¥15 设备精度0.03给多少公差能达到CPK1.33