SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Need help with Select statement!!


Need help with Select statement!!

Author
Message
yasser.akhan
yasser.akhan
Forum Newbie
Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)

Group: General Forum Members
Points: 3 Visits: 4
final project is due tonight at midnight and i cant finish up these select statements

a. Find all those customers who have not purchased anything from Niles Video Inc.
b. Get the total number of DVDs and video tapes sold per genre.
c. Get the average number of DVDs per purchase.


heres the er model



followed by the relational






please let me know if my er model or relational model is wrong
Sean Lange
Sean Lange
SSC-Dedicated
SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)

Group: General Forum Members
Points: 33951 Visits: 17681
Select statements usually come from tables. The pictures don't do much.

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Modens splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Orlando Colamatteo
Orlando Colamatteo
SSCoach
SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)

Group: General Forum Members
Points: 19525 Visits: 14398
Please provide:

1. DDL in the form of CREATE TABLE statements to create your sample tables
2. DML in the form of INSERT INTO statements to populate the sample tables
3. The expected results of your SELECT statements based on that sample data
4. Most importantly: what you have tried so far.

__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
Lynn Pettis
Lynn Pettis
SSC Guru
SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)

Group: General Forum Members
Points: 52294 Visits: 38684
Maybe I will look at this tomorrow.

Cool
Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
yasser.akhan
yasser.akhan
Forum Newbie
Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)

Group: General Forum Members
Points: 3 Visits: 4
Oh srry about that, its a rather long project so i tried to spare some goring detail but here.

CREATE DATABASE Webstore
CREATE TABLE Customers
(
Customer_ID number(5) not null primary key,
Name varchar2(32) not null,
Shipping_Address varchar2(32) not null,
Email varchar2(32) not null,
Credit_Card# integer(16) not null,
);


CREATE TABLE Movies
(
Barcode number(3) not null ,
Title Varchar2(32),
Genre Varchar2(32) not null,
Year Number(4)
Media_Type Char(1) not null,
Cost money not null,
CONSTRAINT Medt primary key (barcode)
);

CREATE TABLE DVD
(
Format char(10) not null,
Cost money not null,
Quantity number(2) not null,
CONSTRAINT Medt
Foreign Key(barcode) references Movies(barcode),
);

CREATE TABLE Videos
(
Format char(10) not null,
Cost money not null,
Quantity number(2) not null,
CONSTRAINT Medt
Foreign Key(barcode) references Movies(barcode),
);



Insert Statement

INSERT INTO Customer VALUES (11111, ‘Mike Smith’, ‘111 Ship Lane, IL 67892’, ‘mikesmith@gmail.com’, 1234 5678 9101 1121);
INSERT INTO Customer VALUES (22222, ‘John Doe’, ‘222 Miss Lane, IL 64592’, ‘jdoe@gmail.com’, 9876 5678 9101 3456);
INSERT INTO Customer VALUES (33333, ‘Rick Slick’, ‘333 tree Lane, IL 61253’, ‘slickrick@gmail.com’, 4589 5980 1256 1631)
INSERT INTO Customer VALUES (44444, ‘Cheap Guy’, ‘444 cheap Lane, IL 60007’, ‘nothing@gmail.com’, 1276 5980 9876 1631)



INSERT INTO Movies VALUES (223, ‘Dark Knight’, ‘Action’, 2013, ‘D’, $20.00);
INSERT INTO Movies VALUES (132, ‘Titanic’, ‘Romance’, 1998, ‘V’, $8.00);
INSERT INTO Movies VALUES (213, ‘Avengers’, ‘Action’, 2013, ‘D’, $20.00);
INSERT INTO Movies VALUES (145, ‘Lion King’, ‘Children’, 1996, ‘V’, $6.00);


INSERT INTO Sales VALUES (10, $28.00, 11/3/2013, 157, 11111);
INSERT INTO Sales VALUES (11, $40.00, 10/28/2013, 289, 22222);
INSERT INTO Sales VALUES (12, $6.00, 11/10/2013, 865, 33333);
INSERT INTO Sales VALUES (13, $20.00, 11/11/2013, 865, 33333);


INSERT INTO DVD VALUES (‘DVDd’, $100.00, 5, 223);
INSERT INTO Video VALUES (‘SVHS’, $32.00, 4, 132 );
INSERT INTO Movies VALUES (‘DVDplus’, $100.00, 5, 213);
INSERT INTO Video VALUES (‘VHS’, $60.00, 10, 145);



i was told to forget about the shopping cart.
Orlando Colamatteo
Orlando Colamatteo
SSCoach
SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)

Group: General Forum Members
Points: 19525 Visits: 14398
That looks like Oracle code Ermm

__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
Orlando Colamatteo
Orlando Colamatteo
SSCoach
SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)

Group: General Forum Members
Points: 19525 Visits: 14398
You;re really making us work over here...

I tried polishing up the SQL you provided so it would run on SQL Server but it's not even close. Syntax errors everywhere, mis-aligned columns on the insert, constraints reffing non-existent columns.

Try again?

Oracle code is fine, we can easily switch it to run on SQL Server and we can write ANSI-standard SELECT statements that will run on both.

PS ...oh yeah, and this time, expected results would be nice, and show us what you have tried ;-)

__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
yasser.akhan
yasser.akhan
Forum Newbie
Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)

Group: General Forum Members
Points: 3 Visits: 4
meh dont worry about it, it was sort of a last ditch effort. thanks for looking at it though
kevaburg
kevaburg
SSCrazy
SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)

Group: General Forum Members
Points: 2323 Visits: 1025
Sorry for saying this but whether it is PL-SQL or T-SQL is somewhat irrelevant......the results you expected are somewhat basic and not particularly taxing. Are you sure this person had the right to expect you to perform a task like this....?
Lynn Pettis
Lynn Pettis
SSC Guru
SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)

Group: General Forum Members
Points: 52294 Visits: 38684
kevaburg (3/25/2013)
Sorry for saying this but whether it is PL-SQL or T-SQL is somewhat irrelevant......the results you expected are somewhat basic and not particularly taxing. Are you sure this person had the right to expect you to perform a task like this....?


Curious, to whom was this comment addressed?

Cool
Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search