﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Contests! / SQLServerCentral.com  / intersting sql puzzle / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Sat, 18 May 2013 01:48:46 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: intersting sql puzzle</title><link>http://www.sqlservercentral.com/Forums/Topic181068-160-1.aspx</link><description>Ok... here it is...[code]DECLARE @SpName varchar(10)SET @SpName = 'Y'SELECT DISTINCT ANTI_MISSILE.antim_id,ANTI_MISSILE.anitm_name FROM DEFUSE_CAPABILITY INNER JOIN ANTI_MISSILE ON DEFUSE_CAPABILITY.antim_id = ANTI_MISSILE.antim_idWHERE DEFUSE_CAPABILITY.antim_id IN (	SELECT antim_id FROM 	(		SELECT Count(*) AS xcnt ,antim_id FROM DEFUSE_CAPABILITY 		WHERE missile_id IN (SELECT missile_id FROM ALIEN_CAPABILITY INNER JOIN SPECIES ON SPECIES.spcid = ALIEN_CAPABILITY.spcid WHERE SPECIES.spcname = @SPname)		Group BY antim_id	) C1	WHERE xcnt &amp;gt;= (SELECT Count(*) FROM ALIEN_CAPABILITY INNER JOIN SPECIES ON SPECIES.spcid = ALIEN_CAPABILITY.spcid WHERE SPECIES.spcname = @SPname)) [/code]Atif Sheikh</description><pubDate>Sat, 09 Aug 2008 03:43:05 GMT</pubDate><dc:creator>Atif-ullah Sheikh</dc:creator></item><item><title>RE: intersting sql puzzle</title><link>http://www.sqlservercentral.com/Forums/Topic181068-160-1.aspx</link><description>does not seem to hard, start with create database create table and so on. hehegood luck</description><pubDate>Thu, 31 Jul 2008 03:22:34 GMT</pubDate><dc:creator>terryj30</dc:creator></item><item><title>RE: intersting sql puzzle</title><link>http://www.sqlservercentral.com/Forums/Topic181068-160-1.aspx</link><description>neat.</description><pubDate>Fri, 07 Mar 2008 17:17:22 GMT</pubDate><dc:creator>RBarryYoung</dc:creator></item><item><title>RE: intersting sql puzzle</title><link>http://www.sqlservercentral.com/Forums/Topic181068-160-1.aspx</link><description>Y dont u make this into a sci-fi hollywood movie and the money it generates can be used to out source this kinda problems and solve it. :P</description><pubDate>Fri, 11 Jan 2008 02:21:50 GMT</pubDate><dc:creator>Jerome.J.N</dc:creator></item><item><title>RE: intersting sql puzzle</title><link>http://www.sqlservercentral.com/Forums/Topic181068-160-1.aspx</link><description>Post some more information !!</description><pubDate>Fri, 04 May 2007 01:06:00 GMT</pubDate><dc:creator>Jaiprakash M Bankolli</dc:creator></item><item><title>RE: intersting sql puzzle</title><link>http://www.sqlservercentral.com/Forums/Topic181068-160-1.aspx</link><description>&lt;P&gt;Okay...goce that was so nice of you to give the whole script...that save much time&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description><pubDate>Wed, 26 Oct 2005 23:16:00 GMT</pubDate><dc:creator>Amol M Vaidya</dc:creator></item><item><title>RE: intersting sql puzzle</title><link>http://www.sqlservercentral.com/Forums/Topic181068-160-1.aspx</link><description>&lt;P&gt;well ,goce you just seem to enjoy criticism....you might as well answer the question for bishu.....i guess that will help more &lt;img src='images/emotions/smile.gif' height='20' width='20' border='0' title='Smile' align='absmiddle'&gt;...&lt;/P&gt;&lt;P&gt;I agree that he should have posted this puzzle somewhere else but after pointing that you might as well help him solve that...&lt;/P&gt;</description><pubDate>Wed, 26 Oct 2005 23:14:00 GMT</pubDate><dc:creator>Amol M Vaidya</dc:creator></item><item><title>RE: intersting sql puzzle</title><link>http://www.sqlservercentral.com/Forums/Topic181068-160-1.aspx</link><description>&lt;P&gt;DECLARE @spcname varchar(50)SET @spcname='Y'&lt;/P&gt;&lt;P&gt;SELECT b.antim_id,anitm_nameFROM(SELECT a.spcid,a.missile_id,b.spcnameFROM Alien_CAPABILITY a INNER JOIN SPECIES b ON a.spcid=b.spcidWHERE &lt;A href="mailto:spcname=@spcname"&gt;spcname=@spcname&lt;/A&gt;) a INNER JOIN DEFUSE_CAPABILITY b ON a.missile_id=b.missile_id INNER JOIN ANTI_MISSILE c ON b.antim_id=c.antim_idGROUP BY b.antim_id ,anitm_nameHAVING count(*)=(SELECT count(*) FROM Alien_CAPABILITY a INNER JOIN SPECIES b ON a.spcid=b.spcid WHERE &lt;A href="mailto:spcname=@spcname"&gt;spcname=@spcname&lt;/A&gt;)&lt;/P&gt;</description><pubDate>Fri, 29 Jul 2005 07:47:00 GMT</pubDate><dc:creator>Vasc</dc:creator></item><item><title>RE: intersting sql puzzle</title><link>http://www.sqlservercentral.com/Forums/Topic181068-160-1.aspx</link><description>Hi all,here is the script I wrote for myself, according to the puzzle specification. It also contains some sample data.&lt;pre&gt;CREATE TABLE SPECIES(  spcid INTEGER primary key,  spcname VARCHAR(100))GOCREATE TABLE ALIEN_MISSILE(  missile_id INTEGER primary key,  missile_name VARCHAR(100),  descr VARCHAR(400))GOCREATE TABLE ALIEN_CAPABILITY(  spcid INTEGER,  missile_id INTEGER,  constraint fk_alien_capability_species foreign key (spcid) references SPECIES(spcid),  constraint fk_alien_capability_alien_missile foreign key (missile_id) references ALIEN_MISSILE(missile_id))GOCREATE TABLE ANTI_MISSILE(  antim_id INTEGER primary key,  anitm_name VARCHAR(100),  anitm_descr VARCHAR(400))GOCREATE TABLE DEFUSE_CAPABILITY(  antim_id INTEGER,  missile_id INTEGER,  constraint fk_defuse_capability_anti_missile foreign key (antim_id) references ANTI_MISSILE(antim_id),  constraint fk_defuse_capability_alien_missile foreign key (missile_id)  references ALIEN_MISSILE(missile_id))GOSET NOCOUNT ONINSERT INTO SPECIES (spcid, spcname) VALUES (1, 'X')INSERT INTO SPECIES (spcid, spcname) VALUES (2, 'Y')INSERT INTO ALIEN_MISSILE(missile_id, missile_name, descr) VALUES (1, 'M-1', 'Missile 1')INSERT INTO ALIEN_MISSILE(missile_id, missile_name, descr) VALUES (2, 'M-2', 'Missile 2')INSERT INTO ALIEN_MISSILE(missile_id, missile_name, descr) VALUES (3, 'M-3', 'Missile 3')INSERT INTO ALIEN_MISSILE(missile_id, missile_name, descr) VALUES (4, 'M-4', 'Missile 4')INSERT INTO ALIEN_CAPABILITY(spcid, missile_id) VALUES (1, 1)INSERT INTO ALIEN_CAPABILITY(spcid, missile_id) VALUES (1, 2)INSERT INTO ALIEN_CAPABILITY(spcid, missile_id) VALUES (1, 3)INSERT INTO ALIEN_CAPABILITY(spcid, missile_id) VALUES (2, 1)INSERT INTO ALIEN_CAPABILITY(spcid, missile_id) VALUES (2, 4)INSERT INTO ANTI_MISSILE(antim_id, anitm_name, anitm_descr) VALUES (1, 'AM-1', 'Anti-missile 1')INSERT INTO ANTI_MISSILE(antim_id, anitm_name, anitm_descr) VALUES (2, 'AM-2', 'Anti-missile 2')INSERT INTO ANTI_MISSILE(antim_id, anitm_name, anitm_descr) VALUES (3, 'AM-3', 'Anti-missile 3')INSERT INTO ANTI_MISSILE(antim_id, anitm_name, anitm_descr) VALUES (4, 'AM-4', 'Anti-missile 4')INSERT INTO DEFUSE_CAPABILITY(antim_id, missile_id) VALUES (1, 1)INSERT INTO DEFUSE_CAPABILITY(antim_id, missile_id) VALUES (1, 2)INSERT INTO DEFUSE_CAPABILITY(antim_id, missile_id) VALUES (1, 3)INSERT INTO DEFUSE_CAPABILITY(antim_id, missile_id) VALUES (1, 4)INSERT INTO DEFUSE_CAPABILITY(antim_id, missile_id) VALUES (2, 1)INSERT INTO DEFUSE_CAPABILITY(antim_id, missile_id) VALUES (2, 2)INSERT INTO DEFUSE_CAPABILITY(antim_id, missile_id) VALUES (3, 1)INSERT INTO DEFUSE_CAPABILITY(antim_id, missile_id) VALUES (3, 2)INSERT INTO DEFUSE_CAPABILITY(antim_id, missile_id) VALUES (3, 3)INSERT INTO DEFUSE_CAPABILITY(antim_id, missile_id) VALUES (4, 1)INSERT INTO DEFUSE_CAPABILITY(antim_id, missile_id) VALUES (4, 2)INSERT INTO DEFUSE_CAPABILITY(antim_id, missile_id) VALUES (4, 4)GO&lt;/pre&gt;Regards,Goce.</description><pubDate>Thu, 16 Jun 2005 04:47:00 GMT</pubDate><dc:creator>Goce Smilevski</dc:creator></item><item><title>RE: intersting sql puzzle</title><link>http://www.sqlservercentral.com/Forums/Topic181068-160-1.aspx</link><description>hey can u post the create script &lt;img src='images/emotions/wink.gif' height='20' width='20' border='0' title='Wink' align='absmiddle'&gt;</description><pubDate>Thu, 16 Jun 2005 04:28:00 GMT</pubDate><dc:creator>Rani Shoura</dc:creator></item><item><title>RE: intersting sql puzzle</title><link>http://www.sqlservercentral.com/Forums/Topic181068-160-1.aspx</link><description>&lt;P&gt;Here's a much smaller teaser.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;READ this code.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;print 'hello, David'/*go&lt;/P&gt;&lt;P&gt;print 'hello, Allen'&lt;/P&gt;&lt;P&gt;go*/print 'Goodbye, All'&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;Before running it, see if you can anticipate what the results will be. You'll be surprised.&lt;/P&gt;</description><pubDate>Wed, 18 May 2005 13:39:00 GMT</pubDate><dc:creator>sara karasik</dc:creator></item><item><title>RE: intersting sql puzzle</title><link>http://www.sqlservercentral.com/Forums/Topic181068-160-1.aspx</link><description>&lt;P&gt;Look up relational division.  Fix the DDL.  &lt;/P&gt;&lt;P&gt; &lt;/P&gt;</description><pubDate>Thu, 12 May 2005 17:09:00 GMT</pubDate><dc:creator>CELKO</dc:creator></item><item><title>RE: intersting sql puzzle</title><link>http://www.sqlservercentral.com/Forums/Topic181068-160-1.aspx</link><description>Hi Thomas,so somebody tried to puzzle you, too :-).I suppose that mail originated from somewhere ... so we can still obtain some more info about the puzzle origin.Regards,Goce.</description><pubDate>Thu, 12 May 2005 01:43:00 GMT</pubDate><dc:creator>Goce Smilevski</dc:creator></item><item><title>RE: intersting sql puzzle</title><link>http://www.sqlservercentral.com/Forums/Topic181068-160-1.aspx</link><description>&lt;P&gt;sorry guys i cannot give a link , i got it as a fwd email.&lt;/P&gt;&lt;P&gt;yes i have little knowledge on sql, but just wanted to get it solved.....&lt;/P&gt;</description><pubDate>Thu, 12 May 2005 01:29:00 GMT</pubDate><dc:creator>bishu thomas</dc:creator></item><item><title>RE: intersting sql puzzle</title><link>http://www.sqlservercentral.com/Forums/Topic181068-160-1.aspx</link><description>Hi Thomas,Why did you post the puzzle as a contest ? It was not listed in the official contests list on SSC. I don't like situations like this, when it is possible that some SSC members abuse the enthusiasm of others. This may destroy the community spirit of the site.Why don't you post the puzzle URL here ? I suppose that many of us are interested in SQL puzzles, so we can test our knowledge, too.According to this part of your post:"my Q1 should return 3000...How to do it.? Will using ALL will help?"I can conclude that you are a newbie to SQL. Why don't you try yourself with easier puzzles ?Regards,Goce.</description><pubDate>Thu, 12 May 2005 01:23:00 GMT</pubDate><dc:creator>Goce Smilevski</dc:creator></item><item><title>RE: intersting sql puzzle</title><link>http://www.sqlservercentral.com/Forums/Topic181068-160-1.aspx</link><description>&lt;P&gt;This is the actual bottle neck in the above puzzle&lt;/P&gt;&lt;P&gt;If i want to select  antim_id from following table using query Q1...which has all the missile_id values returned by another query Q2 .&lt;/P&gt;&lt;P&gt;For eg. if Q2 returns 100,300,400&lt;/P&gt;&lt;P&gt;my Q1 should return 3000...How to do it.? Will using ALL will help?&lt;/P&gt;&lt;P&gt;DEFUSE_CAPABILITY+----------+------------+| antim_id | missile_id |+----------+------------+|     1000 |        100 ||     1000 |        200 ||     2000 |        100 ||     2000 |        200 ||     2000 |        300 ||     3000 |        100 ||     3000 |        200 ||     3000 |        300 ||     3000 |        400 ||     3000 |        500 |+----------+------------+&lt;/P&gt;&lt;P&gt; &lt;/P&gt;</description><pubDate>Thu, 12 May 2005 00:18:00 GMT</pubDate><dc:creator>bishu thomas</dc:creator></item><item><title>RE: intersting sql puzzle</title><link>http://www.sqlservercentral.com/Forums/Topic181068-160-1.aspx</link><description>&lt;P&gt;Its just a puzzle....i stuck up ....&lt;/P&gt;&lt;P&gt;just curious to know the answer........any help ?&lt;/P&gt;</description><pubDate>Wed, 11 May 2005 23:46:00 GMT</pubDate><dc:creator>bishu thomas</dc:creator></item><item><title>RE: intersting sql puzzle</title><link>http://www.sqlservercentral.com/Forums/Topic181068-160-1.aspx</link><description>Why do I think that this is a homework problem?  &lt;img src='images/emotions/wink.gif' height='20' width='20' border='0' title='Wink' align='absmiddle'&gt;</description><pubDate>Wed, 11 May 2005 10:52:00 GMT</pubDate><dc:creator>Russell Shilling</dc:creator></item><item><title>intersting sql puzzle</title><link>http://www.sqlservercentral.com/Forums/Topic181068-160-1.aspx</link><description>&lt;FONT size=2&gt;&lt;P&gt;Independence Day - II&lt;/P&gt;&lt;P&gt;The All Nations United Force (ANUF), formed to protect the human race&lt;/P&gt;&lt;P&gt;against alien attacks, maintains a database of known extra terrestrial&lt;/P&gt;&lt;P&gt;species and the types of missiles that these species are capable of&lt;/P&gt;&lt;P&gt;using.&lt;/P&gt;&lt;P&gt;The ANUF has developed several anti-missiles each of which is capable of&lt;/P&gt;&lt;P&gt;protecting against one or more types of alien missiles. On one dark day&lt;/P&gt;&lt;P&gt;the&lt;/P&gt;&lt;P&gt;ANUF radars signal that several missiles that are known to be originated&lt;/P&gt;&lt;P&gt;from species X are heading towards the Earth. The ANUF Chief of Staff&lt;/P&gt;&lt;P&gt;calls&lt;/P&gt;&lt;P&gt;you and asks to find out if there is a single ANUF anti-missile that can&lt;/P&gt;&lt;P&gt;defuse ALL types of missiles that species X can use. As the application&lt;/P&gt;&lt;P&gt;ANUF&lt;/P&gt;&lt;P&gt;uses does not allow such a query to be answered you are required to&lt;/P&gt;&lt;P&gt;issue a&lt;/P&gt;&lt;P&gt;direct query against the ANUF database and find out the list of&lt;/P&gt;&lt;P&gt;anti-missiles each of which can defuse ALL the missiles that can be used&lt;/P&gt;&lt;P&gt;by&lt;/P&gt;&lt;P&gt;species X.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;For example, assume species X can use missiles M-1, M-2 and M-3. Further&lt;/P&gt;&lt;P&gt;assume ANUF anti-missile AM-1 can defuse {M-1, M-2, M-3, M-4}, ANUF&lt;/P&gt;&lt;P&gt;anti-missile AM-2 can defuse {M-1, M-2} and ANUF anti-missile AM-3 can&lt;/P&gt;&lt;P&gt;defuse {M-1, M-2, M-3}. Now your query should list AM-1 and AM-3 as the&lt;/P&gt;&lt;P&gt;candidate anti-missiles since each of these have potential to defuse ALL&lt;/P&gt;&lt;P&gt;the&lt;/P&gt;&lt;P&gt;missiles that can be used by species X.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;The relational schema of the ANUF missile database is as follows:&lt;/P&gt;&lt;P&gt;SPECIES(spcid INTEGER primary key,&lt;/P&gt;&lt;P&gt;spcname VARCHAR(100));&lt;/P&gt;&lt;P&gt;ALIEN_MISSILE(missile_id INTEGER primary key,&lt;/P&gt;&lt;P&gt;missile_name VARCHAR(100),&lt;/P&gt;&lt;P&gt;descr VARCHAR(400));&lt;/P&gt;&lt;P&gt;ALIEN_CAPABILITY(spcid INTEGER references SPECIES(spcid),&lt;/P&gt;&lt;P&gt;missile_id INTEGER,&lt;/P&gt;&lt;P&gt;references ALIEN_MISSILE(missile_id));&lt;/P&gt;&lt;P&gt;ANTI_MISSILE(antim_id INTEGER primary key,&lt;/P&gt;&lt;P&gt;anitm_name VARCHAR(100),&lt;/P&gt;&lt;P&gt;anitm_descr VARCHAR(400));&lt;/P&gt;&lt;P&gt;DEFUSE_CAPABILITY(antim_id INTEGER references ANTI_MISSILE(antim_id),&lt;/P&gt;&lt;P&gt;missile_id INTEGER references&lt;/P&gt;&lt;P&gt;ALIEN_MISSILE(missile_id));&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;Instructions&lt;/P&gt;&lt;P&gt;1. Your answer should be a single SQL query&lt;/P&gt;&lt;P&gt;2. The query should be database neutral (should conform to the SQL92&lt;/P&gt;&lt;P&gt;standard). You should not use any vendor specific SQL extensions,&lt;/P&gt;&lt;P&gt;user-defined functions or stored procedures.&lt;/P&gt;&lt;P&gt;3. The species name should NOT be hard coded in the query and should&lt;/P&gt;&lt;P&gt;instead&lt;/P&gt;&lt;P&gt;be the parameter marker - "?"&lt;/P&gt;&lt;P&gt;4. The query result should have exactly two columns antim_id and&lt;/P&gt;&lt;P&gt;antim_name.&lt;/P&gt;&lt;P&gt;5. The query should be submitted in a file and should be written in a&lt;/P&gt;&lt;P&gt;single&lt;/P&gt;&lt;P&gt;line.&lt;/P&gt;&lt;/FONT&gt;</description><pubDate>Tue, 10 May 2005 07:57:00 GMT</pubDate><dc:creator>bishu thomas</dc:creator></item></channel></rss>