Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
n MySQL。他的语法可以在MSSQL中使用。如果MySQL中不允许这样做,您可以始终先创建表,然后执行插入tmp_fixtures SELECT DISTINCT…但是为什么robert solution会给我错误:未声明的tmp_fixtures?@_Mysql_Sql - Fatal编程技术网

n MySQL。他的语法可以在MSSQL中使用。如果MySQL中不允许这样做,您可以始终先创建表,然后执行插入tmp_fixtures SELECT DISTINCT…但是为什么robert solution会给我错误:未声明的tmp_fixtures?@

n MySQL。他的语法可以在MSSQL中使用。如果MySQL中不允许这样做,您可以始终先创建表,然后执行插入tmp_fixtures SELECT DISTINCT…但是为什么robert solution会给我错误:未声明的tmp_fixtures?@,mysql,sql,Mysql,Sql,n MySQL。他的语法可以在MSSQL中使用。如果MySQL中不允许这样做,您可以始终先创建表,然后执行插入tmp_fixtures SELECT DISTINCT…但是为什么robert solution会给我错误:未声明的tmp_fixtures?@Spartaok我不确定,可能SELECT INTO在MySQL中无效。他的语法可以在MSSQL中使用。如果MySQL中不允许这样做,您可以始终先创建表,然后执行INSERT-INTO-tmp\u fixtures选择DISTINCT… SEL


n MySQL。他的语法可以在MSSQL中使用。如果MySQL中不允许这样做,您可以始终先创建表,然后执行
插入tmp_fixtures SELECT DISTINCT…
但是为什么robert solution会给我错误:未声明的tmp_fixtures?@Spartaok我不确定,可能SELECT INTO在MySQL中无效。他的语法可以在MSSQL中使用。如果MySQL中不允许这样做,您可以始终先创建表,然后执行
INSERT-INTO-tmp\u fixtures选择DISTINCT…
SELECT player_id, match_id, team_id, count(*) 
FROM fixtures
GROUP BY player_id, match_id, team_id
HAVING COUNT(*) > 1
player_id | match_id  | team_id
  19014       2506172    12573
  19014       2506172    12573
  19015       2506172    12573
  19016       2506172    12573
  19016       2506172    12573
  19016       2506172    12573
player_id | match_id  | team_id
  19014       2506172    12573
  19015       2506172    12573
  19016       2506172    12573
CREATE TABLE IF NOT EXISTS `swp`.`fixtures` (
  `player_id` INT NOT NULL,
  `match_id` INT NOT NULL,
  `team_id` INT NOT NULL,
  INDEX `player_id_idx` (`player_id` ASC),
  INDEX `match_id_idx` (`match_id` ASC),
  INDEX `FK_team_fixtures_id_idx` (`team_id` ASC),
  CONSTRAINT `FK_player_fixtures_id`
    FOREIGN KEY (`player_id`)
    REFERENCES `swp`.`player` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `FK_match_fixtures_id`
    FOREIGN KEY (`match_id`)
    REFERENCES `swp`.`match` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `FK_team_fixtures_id`
    FOREIGN KEY (`team_id`)
    REFERENCES `swp`.`team` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;
CREATE TABLE tmp_fixtures
(
  player_id INT NOT NULL,
  match_id  INT NOT NULL,
  team_id   INT NOT NULL
);

SELECT DISTINCT
       player_id,
       match_id,
       team_id
  INTO tmp_fixtures
  FROM fixtures;

TRUNCATE TABLE fixtures;
ALTER TABLE fixtures ADD PRIMARY KEY (player_id, match_id, team_id);
INSERT INTO fixtures (player_id, match_id, team_id)
  SELECT player_id,
         match_id,
         team_id
  FROM   tmp_fixtures;

DROP TABLE tmp_fixtures;
ALTER TABLE swp.fixtures ADD PRIMARY KEY(player_id, match_id, team_id);
INSERT INTO tbl_temp2 (fld_id)
    SELECT tbl_temp1.fld_order_id
    FROM tbl_temp1 WHERE tbl_temp1.fld_order_id > 100;
CREATE TABLE tmp_fixtures AS 
    SELECT DISTINCT player_id, match_id, team_id FROM fixtures;

TRUNCATE TABLE fixtures;

ALTER TABLE fixtures ADD PRIMARY KEY(player_id, match_id, team_id);

INSERT INTO fixtures (player_id, match_id, team_id)
    SELECT player_id, match_id, team_id FROM tmp_fixtures;

DROP TABLE tmp_fixtures;
DECLARE @i INT = 0

WHILE @i < 6820483
BEGIN
  DELETE FROM f
  FROM (
      SELECT *
      FROM fixtures
      WHERE player_id IN (SELECT player_id FROM fixtures GROUP BY player_id HAVING COUNT(*) > 1)
      LIMIT 1
  ) f

  SET @i = @i + 1
END