SQL Puzzle: Movies With 2 different Villains

List the movies that have exactly two different villains. check the Sample data and expected output below.

Input Data:



Expected Output:



Data Script:



CREATE TABLE Movies
(
	ID INT,
	MovieName NVARCHAR(150),
	Actor NVARCHAR(100),
	Role NVARCHAR(150)
)

INSERT INTO Movies
VALUES
	(1,'Pushpa','AA','Hero'),
	(2,'Pushpa','Sunil','Villain'),
	(3,'Pushpa','Sunil','Villain'),
	(4,'F10','Rocky','Villain'),
	(5,'F10','Jhon','Villain'),
	(6,'Transformers','Nick','Hero'),
	(7,'Transformers','Rock','Villain'),
	(8,'Transformers','Rockey','Villain'),
	(9,'Transformers','vikki','Villain'),
	(10,'Pushpa-2','Sunil','Villain'),
	(11,'Pushpa-2','Fahad','Villain')

SELECT * FROM Movies



Please try to answer the question, if you still not able to get it click below show button to see the answer.

No comments:

Post a Comment