![]() | ![]() |
|
Welcome to the HEXUS.community discussion forums forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and other features. By joining our free community you will have access to post topics, respond to polls and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! |
| |||||||
| Software and web development Databases, graphics, programming, scripting and web development. |
![]() |
| | LinkBack | Thread Tools |
| | #1 (permalink) |
| Hmmm bed Join Date: Jul 2003
Posts: 427
Thanks: 0
Thanked 0 Times in 0 Posts
| SQL Query Ok, I have something i just can't get my head round, spent ages trying to get it to work last night but to no avail, so here goes! I have a query, I wish to get the query to display the customer firstname and surname and the number of videos they have hired, the tables look like this (i have only included the fields i think we need): Customer--- firstname | surname | memberid rental--- memberid | rentalnumber so i was thinking count the number of times the customers memberid appears in *** table and bobs your uncle, well i got it to display the member id along side how many times it occurs: select memberid, count(memberid) from rentalhead1 group by memberid but when ever i try and link/relate it to the customer table, it does not work as i can not use the surname/firstname columsn where a group by is in there! any help would be great, cheers |
| | |
| | #2 (permalink) |
| HEXUS.net Webmaster Join Date: Jul 2003 Location: UK
Posts: 3,112
Thanks: 1
Thanked 0 Times in 0 Posts
| SELECT c.firstname, c.surname, COUNT(c.memberid) AS num_rentals FROM customer AS c, rental AS r WHERE r.memberid=c.memberid GROUP BY c.memberid should do the trick I think |
| | |
| | #3 (permalink) |
| Pixel Abuser Join Date: Nov 2003 Location: Milton Keynes
Posts: 1,523
Thanks: 0
Thanked 0 Times in 0 Posts
| I assume your version is for MySQL Az as i couldnt get it to work on SQL Server - it wasnt happy without an inner join. So if you use MS SQL, heres what you'd need. SELECT Customer.FirstName, Customer.Surname, COUNT(Customer.MemberID) AS [Num_Rentals] FROM Customer INNER JOIN Rental ON Customer.MemberID = Rental.MemberID GROUP BY Customer.MemberID ORDER BY [Num_Rentals] DESC, Customer.Firstname, Customer.Surname |
| | |
| | #6 (permalink) |
| Hmmm bed Join Date: Jul 2003
Posts: 427
Thanks: 0
Thanked 0 Times in 0 Posts
| hey, cheers guys, i'm using Oracle. I got this to work ... SELECT C.memberid, C.SurName, C.FirstName, Count(R.memberid) TotalHired FROM member1 C INNER JOIN rentalhead1 R ON R.MemberId = C.MemberId GROUP BY C.MemberId, C.SurName, C.FirstName thanks for your help |
| | |
![]() |
| Breadcrumb | ||||||
| ||||||
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| My SQL, circular, inefficient ... or neither? | Anders | Software and web development | 14 | 17-11-2004 09:27 PM |
| Learning SQL | Lead_Head | Software and web development | 13 | 26-05-2004 05:54 PM |
| more VBA and SQL 'problems'... | streetster | Software and web development | 7 | 07-01-2004 09:45 PM |
| SQL help | Agent | Software and web development | 23 | 11-11-2003 08:22 AM |