+ Reply to Thread
Page 3 of 4 FirstFirst 1 2 3 4 LastLast
Results 41 to 60 of 72

Thread: SQL Help     submit to reddit submit to twitter

  1. #41
    Salvage Bans
    Join Date
    Jun 2011
    Posts
    927
    BG Level
    5
    FFXI Server
    Sylph

    Quote Originally Posted by octopus View Post
    dunno, but if you take that out the query should work (with the results out of order lol)
    I did, added it to the end and it fixed it and made it in order. Thanks a ton. Gonna start working on Number 5 when i get back from training session with dog.

  2. #42
    Salvage Bans
    Join Date
    Jun 2011
    Posts
    927
    BG Level
    5
    FFXI Server
    Sylph

    Ok working on Number 4.

    repost of question to make easier on people
    Spoiler: show



    select distinct count(*) num_properties, z.city, z.state
    from property p, zip z
    WHERE p.zipcode = z.zipcode
    GROUP BY p.zipcode, z.city, z.state
    ORDER BY num_properties
    desc

    Is this correct or is there a flaw in my logic? Also how do i make it stop showing results after row 15? Actually the question confuses the fuck out of me... did i anwser correctly even?

    Does this count the owners in each city?

    SELECT COUNT (DISTINCT oNo) AS Num_Owners, z.city, z.state
    FROM property p, zip z
    WHERE p.zipcode = z.zipcode
    GROUP BY z.city, z.state
    ORDER BY Num_Owners
    DESC

  3. #43
    Salvage Bans
    Join Date
    Jun 2011
    Posts
    927
    BG Level
    5
    FFXI Server
    Sylph

    Edit:

    Figured it all out! thx for the help!

  4. #44
    Salvage Bans
    Join Date
    Jun 2011
    Posts
    927
    BG Level
    5
    FFXI Server
    Sylph

    Ok new question. For Homework 3 we have to create our own tables and populate them with raw data that he gave us. Whats the best way to do it? Its a massive amount of information and I know there are short cuts but unsure of how exactly the quickest and easiest way to do it is

  5. #45
    Black Belt
    Join Date
    Aug 2005
    Posts
    5,907
    BG Level
    8
    FFXI Server
    Quetzalcoatl

    With pure SQL code, or are you allowed to use a database manager like Microsoft Access? That would surely be the easiest way and fastest way.

  6. #46
    Salvage Bans
    Join Date
    Jun 2011
    Posts
    927
    BG Level
    5
    FFXI Server
    Sylph

    Quote Originally Posted by Uzor View Post
    With pure SQL code, or are you allowed to use a database manager like Microsoft Access? That would surely be the easiest way and fastest way.
    I can use what ever i assume. He provided all the data we need in a word document. I've been trying to import it with by copy pasting it into a excel document, saving it and hitting import. I can go to the import wizard and bring it up and it shows the information in the excel document laid out the way i want. Hit next and it ask for table name and wont let me progress. If i leave it blank it gives me a error saying "table name is not a valid oracle table name" if i type anything and it next it just sits there.

    EDIT:

    kind of getting it to work but keep getting a error saying

    "
    Insert failed for rows 1 through 6
    ORA-02291: INTERGITY CONSTRAIT)
    VOILATED - PARENT KEY NOT FOUND

  7. #47
    Black Belt
    Join Date
    Aug 2005
    Posts
    5,907
    BG Level
    8
    FFXI Server
    Quetzalcoatl

    What's the data you need to insert? The easiest by far would probably be to use Microsoft Access or something similar. I know you can use relationships in Excel too, but it's a whole lot easier to manage primary keys, foreign keys and alternate keys in Access than it is in Excel. You can do it using DDL, but if you're allowed to use Microsoft Access that would be your best bet.

  8. #48
    Salvage Bans
    Join Date
    Jun 2011
    Posts
    927
    BG Level
    5
    FFXI Server
    Sylph

    Quote Originally Posted by Uzor View Post
    What's the data you need to insert? The easiest by far would probably be to use Microsoft Access or something similar. I know you can use relationships in Excel too, but it's a whole lot easier to manage primary keys, foreign keys and alternate keys in Access than it is in Excel. You can do it using DDL, but if you're allowed to use Microsoft Access that would be your best bet.

    Any advice on how to do it with access? I havent used access since high school lol so basically have forgotten everything i know about it. Excel way is working kinda... keeps error saying i voialte my parent key...

  9. #49
    Black Belt
    Join Date
    Aug 2005
    Posts
    5,907
    BG Level
    8
    FFXI Server
    Quetzalcoatl

    It depends on the data.

    Do you already have it written out in a UML datasheet, as a logical notation model, or as a database model? It all depends on the way the data he gave you is presented.

  10. #50
    Salvage Bans
    Join Date
    Jun 2011
    Posts
    927
    BG Level
    5
    FFXI Server
    Sylph

    Quote Originally Posted by Uzor View Post
    It depends on the data.

    Do you already have it written out in a UML datasheet, as a logical notation model, or as a database model? It all depends on the way the data he gave you is presented.
    All the data is laid out in a ms word document in a 4 tables (one for each database table)

  11. #51
    Black Belt
    Join Date
    Aug 2005
    Posts
    5,907
    BG Level
    8
    FFXI Server
    Quetzalcoatl

    Ok, so it's presented as a database model then. How much data is it, exactly? I missed the part where you said it's a massive amount of data...

  12. #52
    Salvage Bans
    Join Date
    Jun 2011
    Posts
    927
    BG Level
    5
    FFXI Server
    Sylph

    Each table has 3-7 collums and 6-200 rows

  13. #53
    Black Belt
    Join Date
    Aug 2005
    Posts
    5,907
    BG Level
    8
    FFXI Server
    Quetzalcoatl

    Well, it's hard to judge without seeing it, but is any of the data overlapping?

    Based on the error you get in your edited post, it seems like you're using the wrong primary key(s), or copy/pasting the tables in the wrong order, which would suggest a lot or some of the data uses foreign keys (which is probably what he's trying to teach you I'm guessing)

  14. #54
    Salvage Bans
    Join Date
    Jun 2011
    Posts
    927
    BG Level
    5
    FFXI Server
    Sylph

    Quote Originally Posted by Uzor View Post
    Well, it's hard to judge without seeing it, but is any of the data overlapping?

    Based on the error you get in your edited post, it seems like you're using the wrong primary key(s), or copy/pasting the tables in the wrong order, which would suggest a lot or some of the data uses foreign keys (which is probably what he's trying to teach you I'm guessing)
    I think i figured it out, I took the class last semester and remembered the way he laid it out is retarded. I have to create the tables, populate them, then add the constraints or it wont work lol. So droped them and tried to populate and worked fine

    Ok i take that back i got 2/4 tables populated

  15. #55
    Black Belt
    Join Date
    Aug 2005
    Posts
    5,907
    BG Level
    8
    FFXI Server
    Quetzalcoatl

    Well there you go, good you figured it out

    Either way, you should consider exploring Microsoft Access or something similar if you're going to take the course, it's a really good program and gives you a much better overview of data, tables and relationships, and you can run SQL-queries from inside the program, too. Then again, our teachers might have recommended it for computer science since we get all 100+ microsoft products for free. Either way, I really like it, takes a little getting used to though

  16. #56
    Salvage Bans
    Join Date
    Jun 2011
    Posts
    927
    BG Level
    5
    FFXI Server
    Sylph

    Quote Originally Posted by Uzor View Post
    Well there you go, good you figured it out

    Either way, you should consider exploring Microsoft Access or something similar if you're going to take the course, it's a really good program and gives you a much better overview of data, tables and relationships, and you can run SQL-queries from inside the program, too. Then again, our teachers might have recommended it for computer science since we get all 100+ microsoft products for free. Either way, I really like it, takes a little getting used to though
    I'll look into it thanks. Ok one error im getting is because my date is formatted wrong. In the input its formated like this "day-month-year" (15-jul-13) in the wizard its asking how i format it so how do i tell it?

    nvm DD-MON-YY thx!

    Ok new problem poped up lol. When i import this data. The last field is decimals (3.0, 3.5, ext) But when i try to import its saying

    "Insert failed for rows 1 through 50
    ora-00001: unique constraint voilated. If i ignore all errors it adds them but leaves out anything that isant a whole number (adds 3.0 but ignores 3.5 and doesnt add them)


  17. #57
    Black Belt
    Join Date
    Aug 2005
    Posts
    5,907
    BG Level
    8
    FFXI Server
    Quetzalcoatl

    You already have that data somewhere else, and it's set to not allow duplicates. You either need to change it so that it's not set as a primary key, or if it's not a primary key, change it so that it allows duplicates (you might have it set to "index - no duplicates" rather than "index - allow duplicates", or "no")

  18. #58
    Salvage Bans
    Join Date
    Jun 2011
    Posts
    927
    BG Level
    5
    FFXI Server
    Sylph

    Quote Originally Posted by Uzor View Post
    You already have that data somewhere else, and it's set to not allow duplicates. You either need to change it so that it's not set as a primary key, or if it's not a primary key, change it so that it allows duplicates (you might have it set to "index - no duplicates" rather than "index - allow duplicates", or "no")
    I used:

    create table worksOnBLF(
    empNo number(6) not null,
    projNo number(4) not null,
    dateWorked date primary key,
    hoursWorked number(3) not null);


    Actually empNo + projNo + dateworked are suppose to be the primary key but i dont know how to code that :/ but at the moment date worked is the primary key



    Raw Data for Works On
    Spoiler: show

    empNo projNo dateWorked hoursWorked
    585049 1336 22-Feb-2013 3.00
    392899 1905 22-Feb-2013 8.00
    346278 2485 26-Feb-2013 5.25
    352495 4599 27-Feb-2013 3.25
    360138 4982 1-Mar-2013 5.25
    579977 3120 2-Mar-2013 8.50
    745164 8076 6-Mar-2013 1.25
    662608 3120 17-Mar-2013 0.25
    360138 4982 17-Mar-2013 2.25
    182880 3120 26-Mar-2013 1.50
    579977 6693 28-Mar-2013 5.00
    745164 4599 1-Apr-2013 3.50
    128861 4918 1-Apr-2013 3.50
    585049 1838 10-Apr-2013 7.75
    742541 1905 10-Apr-2013 5.75
    392899 2317 10-Apr-2013 7.00
    948201 2405 10-Apr-2013 8.00
    547272 1336 11-Apr-2013 4.00
    533455 1905 11-Apr-2013 7.00
    485284 4599 14-Apr-2013 7.00
    117655 2007 17-Apr-2013 1.00
    585049 1336 19-Apr-2013 8.00
    392899 3012 19-Apr-2013 8.00
    579977 3120 19-Apr-2013 5.00
    349024 1336 24-Apr-2013 2.25
    394200 1905 24-Apr-2013 2.25
    943346 6693 29-Apr-2013 5.00
    906728 6444 2-May-2013 5.25
    742541 2403 3-May-2013 4.50
    490577 2007 10-May-2013 0.25
    536988 1838 11-May-2013 5.00
    640224 3012 11-May-2013 7.25
    182880 3120 13-May-2013 3.00
    650590 4918 13-May-2013 0.75
    906728 2405 14-May-2013 1.75
    650590 4982 16-May-2013 8.75
    422712 1336 28-May-2013 0.25
    742541 2317 28-May-2013 5.25
    128861 4982 28-May-2013 3.00
    369042 8076 28-May-2013 2.25
    943346 3120 31-May-2013 2.75
    650590 2485 2-Jun-2013 3.25
    640224 3012 2-Jun-2013 2.25
    547272 1336 5-Jun-2013 4.75
    392899 1905 5-Jun-2013 5.00
    503581 2407 11-Jun-2013 1.50
    221223 4567 11-Jun-2013 8.00
    394200 7002 15-Jun-2013 1.25
    925206 1336 19-Jun-2013 7.25
    742541 2317 19-Jun-2013 5.75
    943346 3120 22-Jun-2013 2.25
    939206 3120 24-Jun-2013 7.00
    503581 4567 26-Jun-2013 6.50
    650590 2485 28-Jun-2013 3.25
    165553 2485 30-Jun-2013 4.00
    342561 1991 14-Jul-2013 8.25
    585049 1336 15-Jul-2013 8.00
    394200 3012 15-Jul-2013 7.25
    349024 1838 19-Jul-2013 5.50
    394200 2403 19-Jul-2013 3.25
    745164 4599 19-Jul-2013 2.75
    394200 1905 23-Jul-2013 6.50
    171562 4986 23-Jul-2013 0.25
    346278 2485 24-Jul-2013 2.25
    360138 2485 24-Jul-2013 6.25
    128861 4289 25-Jul-2013 1.25
    206298 2407 26-Jul-2013 6.00
    171562 4982 27-Jul-2013 8.25
    269749 3120 28-Jul-2013 5.00
    939206 3120 28-Jul-2013 2.00
    585049 1336 31-Jul-2013 4.00
    394200 7002 31-Jul-2013 5.25
    588966 4982 3-Aug-2013 6.00
    848115 4567 4-Aug-2013 2.25
    745164 2405 5-Aug-2013 2.00
    809804 4567 5-Aug-2013 1.75
    182880 6693 7-Aug-2013 8.00
    349024 1838 10-Aug-2013 5.75
    640224 1905 10-Aug-2013 7.75
    538609 2485 14-Aug-2013 5.25
    277042 4567 14-Aug-2013 3.75
    617417 4918 14-Aug-2013 5.00
    585049 1336 15-Aug-2013 5.75
    392899 1905 15-Aug-2013 6.25
    360138 2485 21-Aug-2013 7.25
    360138 4986 21-Aug-2013 2.00
    943346 1991 25-Aug-2013 6.25
    948201 2405 1-Sep-2013 8.00
    843818 2407 9-Sep-2013 7.75
    547272 1838 12-Sep-2013 4.25
    533455 1905 12-Sep-2013 1.50
    742541 3012 20-Sep-2013 2.75
    585049 1838 23-Sep-2013 6.50
    640224 1905 23-Sep-2013 4.25
    433775 2007 24-Sep-2013 1.50
    538609 2485 4-Oct-2013 0.25
    198252 2407 6-Oct-2013 4.50
    617417 2485 8-Oct-2013 5.50
    948201 8076 8-Oct-2013 1.25
    271957 2007 9-Oct-2013 5.50
    809804 2007 9-Oct-2013 8.00
    360138 4986 11-Oct-2013 3.25
    939206 1991 12-Oct-2013 0.25
    547272 1838 15-Oct-2013 1.00
    360138 4289 15-Oct-2013 3.75
    640224 7002 15-Oct-2013 6.00
    394200 1905 17-Oct-2013 1.00
    392899 1905 18-Oct-2013 3.25
    462463 1991 24-Oct-2013 5.25
    360138 4918 24-Oct-2013 0.25
    588966 4918 31-Oct-2013 4.50
    369042 8076 31-Oct-2013 1.00
    128861 2485 3-Nov-2013 3.00
    128861 4918 3-Nov-2013 7.00
    342561 6693 5-Nov-2013 8.00
    269749 6693 15-Nov-2013 5.50
    422712 1336 16-Nov-2013 2.25
    742541 1905 16-Nov-2013 7.25
    462463 6693 17-Nov-2013 0.50
    943346 1991 18-Nov-2013 8.75
    206298 4567 19-Nov-2013 7.00
    906728 6444 20-Nov-2013 1.25
    906728 2405 21-Nov-2013 0.50
    269749 1991 24-Nov-2013 7.75
    269749 3120 25-Nov-2013 7.00
    485284 4599 26-Nov-2013 2.25
    198252 4567 30-Nov-2013 2.25
    422712 1838 1-Dec-2013 1.50
    742541 3012 1-Dec-2013 6.00
    538609 4289 5-Dec-2013 0.25
    433775 2007 6-Dec-2013 6.25
    422712 1838 7-Dec-2013 5.50
    392899 2403 7-Dec-2013 7.25
    182880 1991 8-Dec-2013 5.50
    352495 2405 8-Dec-2013 3.75
    360138 4918 9-Dec-2013 7.00
    640224 1905 10-Dec-2013 7.75
    650590 4982 16-Dec-2013 5.75
    485284 4599 21-Dec-2013 7.25
    485284 2405 23-Dec-2013 6.00
    589559 2007 5-Jan-2014 2.50
    939206 6693 5-Jan-2014 6.00
    588966 4986 6-Jan-2014 1.25
    349024 1336 12-Jan-2014 2.75
    394200 7002 12-Jan-2014 3.25
    742541 1905 13-Jan-2014 3.25
    269749 6693 13-Jan-2014 2.75
    589559 4567 14-Jan-2014 1.25
    490577 2007 19-Jan-2014 3.50
    579977 3120 23-Jan-2014 6.50
    547272 1838 3-Feb-2014 1.75
    394200 1905 3-Feb-2014 7.50
    617417 4289 5-Feb-2014 2.25
    269749 3120 6-Feb-2014 6.75
    226827 6444 8-Feb-2014 4.25
    171562 2485 10-Feb-2014 4.50
    538609 2485 10-Feb-2014 8.25
    117655 2007 12-Feb-2014 1.00
    182880 6693 12-Feb-2014 6.50
    422712 1838 14-Feb-2014 6.00
    392899 3012 14-Feb-2014 5.75
    547272 1336 20-Feb-2014 7.75
    650590 4982 20-Feb-2014 2.25
    392899 7002 20-Feb-2014 7.50

  19. #59
    Black Belt
    Join Date
    Aug 2005
    Posts
    5,907
    BG Level
    8
    FFXI Server
    Quetzalcoatl

    That's why, because you only have date worked as primary key. Look at the first two:

    585049 1336 22-Feb-2013 3.00
    392899 1905 22-Feb-2013 8.00

    Since you only have dateWorked as a primary key, it see that both of them have the same value, and will not allow you to enter them as it would create duplicate entries. If you use all three as a primary key (which you should; primary key is the least amount of information needed to extract a unique entry), it would look at:

    585049 1336 22-Feb-2013 3.00
    392899 1905 22-Feb-2013 8.0

    and see that it's different entries, and will therefor allow you to input the data correctly.

  20. #60
    Salvage Bans
    Join Date
    Jun 2011
    Posts
    927
    BG Level
    5
    FFXI Server
    Sylph

    Quote Originally Posted by Uzor View Post
    That's why, because you only have date worked as primary key. Look at the first two:

    585049 1336 22-Feb-2013 3.00
    392899 1905 22-Feb-2013 8.00

    Since you only have dateWorked as a primary key, it see that both of them have the same value, and will not allow you to enter them as it would create duplicate entries. If you use all three as a primary key (which you should; primary key is the least amount of information needed to extract a unique entry), it would look at:

    585049 1336 22-Feb-2013 3.00
    392899 1905 22-Feb-2013 8.0

    and see that it's different entries, and will therefor allow you to input the data correctly.
    How do I code it to make all 3 the primary key?


    create table worksOnBLF(
    empNo number(6) PRIMARY KEY,
    projNo number(4) PRIMARY KEY,
    dateWorked date primary key,
    hoursWorked number(3) not null);

    fails me lol i suck horribly at database

    also tried:

    create table worksOnBLF(
    empNo number(6) NOT NULL,
    projNo number(4) NOT NULL,
    dateWorked date,
    hoursWorked number(3) not null,
    primary key (empNo, projNo, dateWorked));

    and it failed

Similar Threads

  1. SQL Database - Help studying for Test
    By Aylee in forum Tech
    Replies: 3
    Last Post: 2013-11-06, 14:56
  2. SQL Help
    By Buffy in forum Tech
    Replies: 7
    Last Post: 2013-10-18, 18:43
  3. SQL help
    By Saga in forum Tech
    Replies: 3
    Last Post: 2012-11-29, 18:24
  4. SQL help
    By saracrow in forum Tech
    Replies: 4
    Last Post: 2011-07-01, 00:22