私はSQLを少しいじっているので、就職の面接で尋ねられたとしても、SQLについて完全に無知というわけではありません。私の友人は最近、インタビューで次の質問をされましたが、彼はそれを理解できませんでした.SQLをきちんと知っている職場の人に尋ねましたが、彼は知りませんでした. この問題に答えて、それがどのように機能するか説明してもらえますか? お願いします?
*問題*
データベースの正規化 (または正規化の欠如) は、多くの場合、開発者にとって課題となります。
次の 3 つのフィールドを含む従業員のデータベース テーブルを考えてみましょう。
EmployeeID
EmployeeName
EmailAddresses
一意の EmployeeID で識別されるすべての従業員は、EmailAddresses フィールドに 1 つ以上のカンマ区切りの @rockauto.com 電子メール アドレスを持つことができます。
データベース テーブルは次のように定義されます。
CREATE TABLE Employees
(
EmployeeID int UNSIGNED NOT NULL PRIMARY KEY,
EmployeeName varchar(50) NOT NULL,
EmailAddresses varchar(40) NOT NULL ,
PRIMARY KEY(EmployeeID)
);
テスト目的で、いくつかのサンプル データを次に示します。
INSERT INTO Employees (EmployeeID, EmployeeName, EmailAddresses) VALUES
('1', 'Bill', 'bill@companyx.com'),
('2', 'Fred', 'fred@companyx.com,freddie@companyx.com'),
('3', 'Fred', 'fredsmith@companyx.com'),
('4', 'Joe', 'joe@companyx.com,joe_smith@companyx.com');
ここでのタスクは、上記のサンプル データに対して次の出力を表示する単一の MySQL SELECT クエリを作成することです。
Employee EmailAddress
Bill bill@companyx.com
Fred (2) fred@companyx.com
Fred (2) freddie@companyx.com
Fred (3) fredsmith@companyx.com
Joe joe@companyx.com
Joe joe_smith@companyx.com
同姓同名(この場合は「フレッド」)が複数存在するため、カッコ内にEmployeeIDが含まれていることに注意してください。
クエリは、MySQL バージョン 5.1.41 互換の構文で記述する必要があります。順序付けは、標準的なデータベースの昇順である「ORDER BY EmployeeID ASC」を使用して行われると想定する必要があります。
この問題では、単一の SQL SELECT クエリを送信する必要があります。クエリは、妥当な時間内に 1000 レコードのテーブルを処理できる必要があります。