Discussion in 'Python' started by mmcclaf, Feb 26, 2009.

  1. mmcclaf

    mmcclaf Guest

    I have to make some queries for 4 tables I have. The following
    relations are:

    Classes(class, type, country, numGuns, bore, displacement)
    Ships (name, class, launched)
    Battles (name, date)
    Outcomes (ship, battle, result)

    The three queries I'm stuck on are the following:

    1. Find the classes that have only one ship as a member of that class
    (not all ships are listed in the Ship table)
    2. Find the countries that had both battleships and battlecruisers
    (those fall under type in Classes)
    3. Find those ships that "lived to fight another day"; they were
    damaged in one battle, but later fought in another.

    The best way for me to understand would be relational algebra for each
    of the statements.

    Any help in this would be greatly appreciated.
    mmcclaf, Feb 26, 2009
    1. Advertisements

  2. mmcclaf

    Gary Herron Guest

    Sounds like a homework assignment. Good luck with it.
    Gary Herron, Feb 26, 2009
    1. Advertisements

  3. mmcclaf

    Murray Guest

    It is, however I was able to get the first 8 done, I am struggling with
    these 3 particular ones. I have to make an SQL file based off of it, so this
    seems to be a blockage in my works.

    -----Original Message-----
    From: Gary Herron [mailto:]
    Sent: Thursday, February 26, 2009 1:46 AM
    To: mmcclaf;
    Subject: Re: Queries

    Sounds like a homework assignment. Good luck with it.

    No virus found in this incoming message.
    Checked by AVG - www.avg.com
    Version: 8.0.237 / Virus Database: 270.11.3/1971 - Release Date: 02/25/09
    Murray, Feb 26, 2009
  4. mmcclaf

    Steve Holden Guest

    Murray wrote:
    [top-posting corrected]
    Investigate a GROUP BY solution that selects groups having a count of 1.

    Look at EXISTS for one possible solutions.
    attitude of each ship is stored, so I don't think I can give you any
    help at all with this one.
    Good luck with the homework. Remember to acknowledge the help you've had
    from this list (particularly your earlier issues: here you just have hints).

    Steve Holden, Feb 26, 2009
  5. mmcclaf

    mmcclaf Guest

    Yeppers always do. And thanks! As for the number 3 one... to know if
    they were damaged would appear in "Result" of the Outcomes table
    mmcclaf, Feb 26, 2009
  6. mmcclaf

    mmcclaf Guest

    Another problem with this assignment... I have to list all the ships
    mentioned in the database. All the ships may not appear in the Ships
    relations... I said the following in algebraic expression

    SELECT name(Ships UNION (SELECT ship (Outcome UNION(SELECT class

    Would that work?
    mmcclaf, Feb 26, 2009
  7. mmcclaf

    Steve Holden Guest

    Dennis Lee Bieber wrote:
    A rather fine point, but technically all that's required is the the
    united *queries* have the same number and type of columns. I assume that
    the OP was selecting *, though ...

    Steve Holden, Feb 27, 2009
  8. mmcclaf

    mmcclaf Guest

    This came in the Python groups, and I put one up in the database
    group, since I will later have to use Python to access the SQL file,
    so therefore tackling one thing at a time. Also, there were no answers
    that were coming up in the .database group.

    This meant that some ships weren't listed in the Ship table provided
    but did show up in the Outcome. Therefore, they are not directly
    referenced one to the other.
    What is meant by this statement?

    So in short of the responses given, I need to study further: GROUP BY,
    HAVING, AS, COUNT, and subselect queries, right?

    The relational algebra, I am able to translate it into SQL, or most of
    it, meaning turning it into the queries of SQL. This is not an
    advanced database course, but more a basic intro to database systems.
    mmcclaf, Feb 27, 2009
  9. Uhm... To me, an "SQL file" is a file containing SQL statements. It
    is NOT a database.

    This is part of an SQL file (it's a backup from a MySQL database)

    -- MySQL Administrator dump 1.4
    -- ------------------------------------------------------
    -- Server version 5.0.24a-community-max-nt-log

    /*!40101 SET NAMES utf8 */;


    -- Create schema bestiaria

    USE bestiaria;

    -- Definition of table `artlinks`

    DROP TABLE IF EXISTS `artlinks`;
    CREATE TABLE `artlinks` (
    `ID` int(11) NOT NULL auto_increment,
    `category` enum('archive','artist','zine','reference','news') NOT NULL
    default 'archive',
    `name` varchar(75) NOT NULL default '',
    `URL` varchar(75) NOT NULL default '',
    `banner` varchar(75) default NULL,
    `width` int(11) default NULL,
    `height` int(11) default NULL,
    `description` varchar(250) default NULL,

    -- Dumping data for table `artlinks`

    /*!40000 ALTER TABLE `artlinks` DISABLE KEYS */;
    INSERT INTO `artlinks`


    Artists\' Image Archive"'),

    subsuming the former <i>Lothlorien</i> and <i>Zone47</i> subsites'),
    (5,'archive','The Orlando Furry
    (6,'archive','Side 7','http://www.side7.com/',NULL,NULL,NULL,'&quot;the
    Artist\'s Archive&quot;'),

    Image Archives'),
    Art','http://www.deviantart.com/',NULL,NULL,NULL,'An online artist
    collective and marketplace. Various genres.'),
    (8,'archive','YERF Archives on
    ArtSpots','http://yerf.artspots.com/',NULL,NULL,NULL,'Formerly known as
    <i>The Squeeky Clean Furry Archives</I>. YERF.com has shutdown and
    ArtSpots is archiving the directories of those artists wanting them
    Centaur Fanzine!&quot; (although the definition of &quot;centaur&quot;
    is rather loose)'),

    for Artists&quot;'),
    Press showcases quality furry fiction in book and magazine format.'),
    (12,'artist','Theresa Larsson: Aspects of
    Studios is geared to provide high quality art for print, web and
    multimedia as well as practical models, maquettes, prototypes and
    concepts.&quot; (from their website)'),
    (16,'artist','White Pony
    known as <i>Beth Productions</i>.'),


    (20,'artist','Eric &quot;Coyote&quot;
    (22,'artist','Synnabar (Stephanie M.

    (27,'artist','SummerDragoness.com (Hannah

    Tracy Butler, Candy Palmer, and Cynthia Rowen'),
    (29,'artist','JC Amberlyn (aka
    (30,'artist','Becky\'s Wildlife &amp; Fantasy

    (33,'artist','GoldenWolfen (Christy
    (35,'artist','Nethersphere (Stephanie D.

    literature, music, and discussion forums'),
    (39,'reference','Furry Is...','b_furryis.html',NULL,NULL,NULL,'An essay
    by Chuck Melville'),
    (40,'reference','The State of Furry','b_stateof.html',NULL,NULL,NULL,'A
    1996 Usenet article by Chuck Melville'),

    specific wiki-type encyclopedia'),

    wiki-type encyclopedia'),
    their words: \"Unusually Good Information\"'),
    Furs','http://www.dutchfurs.com/',NULL,NULL,NULL,'News, art, and more...
    with a Dutch perspective'),

    Stories, Poetry, and Music'),
    (46,'reference','A Defense of Furry
    Fandom','b_defense.html',NULL,NULL,NULL,'A 2006 essay by \'Coyoty\' Dave
    (47,'reference','What are you guys actually fans of,
    though?','b_fans_of.html',NULL,NULL,NULL,'A 2006 essay by \'Coyoty\'
    Dave Wright'),

    (49,'archive','Furry Art
    Pile','http://www.furryartpile.com',NULL,NULL,NULL,'&quot;an art
    community for <b>furry artists</b> and <b>connoisseurs</b>.&quot;');
    /*!40000 ALTER TABLE `artlinks` ENABLE KEYS */;


    SQL is a nearly standardized language used to make queries into a
    database; the language maps fairly closely to the structures used by
    most relational database engines, but a relational database is not a
    requirement (though I pity the person that has to write an SQL frontend
    for an old hierarchical database engine).

    About 90% of the junk for sale spam that shows up in
    comp.lang.python is posted by people using gmail accounts. As a result,
    my newsreader is configured to not download messages in the group if the
    "from" address contains gmail. When seeing a something potentially
    interesting quoted by some other responder, I can use the "references"
    headers to instruct my news reader to retrieve specific messages -- such
    retrieval bypasses the kill filter.

    I'm making an effort to see if I can get gmane to pick up messages
    that are otherwise killed... Not sure how effective that is. It found
    this (your) message, but that's only because I had it fetch the most
    recent 50 headers -- not part of the normal "get new" run.
    Since it's homework, we (this group) won't be giving direct SQL
    .... and formal relational algebra is a notation many users of database
    engines like MySQL, SQLite, Access/JET, Visual FoxPro, Paradox, Sybase,
    etc. have never encountered -- heck, Access tries to hide SQL from the
    user via a form of QBE interface.

    If I were to attempt a textual version of relational algebra, you'd
    be getting something on the order of:

    t1 = Ships x Classes
    t2 = restrict t1(Ships.class = Classes.class)
    res = project t2(Ships.name, Classes.class, Classes.country)

    instead of straight forward SQL

    select Ships.name, Classes.class, Classes.country from Ships
    inner join Classes
    on Ships.class = Classes.class

    Wulfraed Dennis Lee Bieber KD6MOG

    (Bestiaria Support Staff: )
    Dennis Lee Bieber, Feb 28, 2009
  10. mmcclaf

    Steve Holden Guest

    I think the real problem is that the database design the OP is using os
    far from normalized. This will tend to contort the logic, as well as
    making the programming harder to understand.

    Steve Holden, Feb 28, 2009
  11. mmcclaf

    mmcclaf Guest

    So basically you are complaining that groups don't pick up post by
    GMail users?

    As for the SQL thing, you still don't see how I am linking this to
    SQL? I have to make in your terms: a textual representation of the
    statements I'd make in SQL. The statement I made with the bold SELECT,
    etc, replace those with the relational algebra symbols, hence needing
    to make a relational algebra expression.
    I never said I wanted direct SQL statements, moreso guidance as to
    what direction I should be heading for each of the queries. I just
    wanted to make sure that there might not be other things I might want
    to study as well that might be required for the queries. Try not to
    interpret what isn't there... I'm looking for help, not direct answers.
    mmcclaf, Feb 28, 2009
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.