У меня есть следующий запрос, который отлично выполняется в MySQL, но он вызывает у меня проблемы, когда я выполняю его на MS SQL Server:
SELECT failedlogins.*, siteprofiles.failedLogins AS max,
COUNT(failedlogins.id) AS total
FROM failedlogins RIGHT JOIN siteprofiles ON failedlogins > 0
WHERE computerName LIKE 'some awesome name' AND timeStamp > 1340752043
GROUP BY computerName
Я получаю следующие ошибки:
Msg 8120, Level 16, State 1, Line 2
Column 'failedlogins.id' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Msg 8120, Level 16, State 1, Line 2
Column 'failedlogins.timeStamp' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Msg 8120, Level 16, State 1, Line 2
Column 'failedlogins.userName' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Msg 8120, Level 16, State 1, Line 2
Column 'siteprofiles.failedLogins' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Я думаю, что это как-то связано с RIGHT JOIN
, но я не знаю, как это решить.
В качестве примечания: если вы не знакомы с MySQL, я правильно присоединил единственную строку из siteprofiles
к таблице failedlogins
. Обычно вы видите знак =
, чтобы поставить отметку "Нравится" две строки из нескольких таблиц. В MySQL, если вы выбираете только одну строку для присоединения к таблице и не используете оператор равенства для связывания строк вместе, он присоединит строку к каждой возвращаемой строке.
Может ли кто-нибудь помочь мне отладить приведенное выше утверждение?
РЕДАКТИРОВАТЬ:
Вот SQL, который строит таблицу failedlogins
:
CREATE TABLE failedlogins (
"id" int NOT NULL,
"timeStamp" int NOT NULL,
"computerName" NTEXT NOT NULL,
"userName" NTEXT NOT NULL,
PRIMARY KEY ("id")
) ;
и таблица siteprofiles
:
CREATE TABLE siteprofiles (
"id" int NOT NULL,
"siteName" varchar(200) NOT NULL,
"paddingTop" tinyint NOT NULL,
"paddingLeft" tinyint NOT NULL,
"paddingRight" tinyint NOT NULL,
"paddingBottom" tinyint NOT NULL,
"width" int NOT NULL,
"height" int NOT NULL,
"sideBar" text NOT NULL,
"auto" text NOT NULL,
"siteFooter" text NOT NULL,
"author" varchar(200) NOT NULL,
"language" varchar(15) NOT NULL,
"copyright" varchar(200) NOT NULL,
"description" NTEXT NOT NULL,
"meta" text NOT NULL,
"timeZone" varchar(20) NOT NULL,
"welcome" text NOT NULL,
"style" varchar(200) NOT NULL,
"iconType" text NOT NULL,
"spellCheckerAPI" varchar(50) NOT NULL,
"saptcha" text NOT NULL,
"question" NTEXT NOT NULL,
"answer" NTEXT NOT NULL,
"failedLogins" int NOT NULL,
PRIMARY KEY ("siteName")
);
INSERT INTO siteprofiles (id, siteName, paddingTop, paddingLeft, paddingRight, paddingBottom, width, height, sideBar, auto, siteFooter, author, language, copyright, description, meta, timeZone, welcome, style, iconType, spellCheckerAPI, saptcha, question, answer, failedLogins) VALUES
(1, 'The Bell News Magazine', 0, 0, 0, 0, 260, 180, 'Right', '', '<p>© 2011 The Bell News Magazine</p>', 'The Bell News Magazine', 'en-US', '© 2011 The Bell News Magazine', 'The collaborative, innovative Bell News Magazine', 'The Bell News Magazine, The PAVCS Bell News Magazine, The Pennsylvania Virtual Charter School Bell News Magazine, Pennsylvania Virtual Charter School Bell News Magazine, Bell News Magazine, Bell News, Bell Magazine, The Bell Magazine, The Bell News', 'America/New_York', 'Ads', 'onlineUniversity.css', 'gif', 'jmyppg6c5k5ajtqcra7u4eql4l864mps48auuqliy3cccqrb6b', 'auto', '', '', 5);
Спасибо за уделенное время.
ON failedlogins
- неполное состояние - person zerkms   schedule 28.06.2012