![]() |
|
Welcome to the Computer Webmaster Gaming Console Graphics Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
| |||||||
| Database Database problems or need to ask a question? maybe something to do with sql injections or a database software question. Database topics cover MySQL, PostgreSQL, Oracle, SQL Server or anything else related to databases. |
![]() |
| | LinkBack | Thread Tools | Display Modes |
| | #1 | ||
| Hi all, I've 3 tables. The first is a table of customers, the second a table of orders and the third a table of questions. I've to provide a table with the customerid, the number of orders and the number of questions. For every order and every question I've a new record in those table. The tables are quite huge, so I can't send the structure but basically in the 3 tables they are the customerid number to link for. As I general idea I'd like something like: select name from customer, count(ordersid) from orders, count (questionid) from customer left join orders on customer.customerid = order.customerid left join questions on customer.customerid = questions.customerid Is this possible ? how ? | |||
|
| Advertisements |
| | #2 | ||
| "Bob Bedford" <bob@bedford.com> a écrit dans le message de news:467a93d0$0$3789$5402220f@news.sunrise.ch... > > select name from customer, count(ordersid) from orders, count (questionid) > from customer > left join orders on customer.customerid = order.customerid > left join questions on customer.customerid = questions.customerid > > Is this possible ? how ? try to add "group by customerid" (look at this recent thread "speedest way to handle a select table1,count(table2) where table1.idtable1=table2.idtable1 ?") | |||
|
| | #3 | ||
| "patrice" <patrice_labracherie_nospam@free.fr> a écrit dans le message de news: 467aa3ca$0$19103$426a74cc@news.free.fr... > "Bob Bedford" <bob@bedford.com> a écrit dans le message de > news:467a93d0$0$3789$5402220f@news.sunrise.ch... >> >> select name from customer, count(ordersid) from orders, count >> (questionid) >> from customer >> left join orders on customer.customerid = order.customerid >> left join questions on customer.customerid = questions.customerid >> >> Is this possible ? how ? > > try to add "group by customerid" > (look at this recent thread "speedest way to handle a select > table1,count(table2) where table1.idtable1=table2.idtable1 ?") it works when I've only one count(), but if I've 2 counts from 2 diffent tables, it multiplies the result of the first count by the result of the second I've 2 tables from wich I must do a count and I can't get a correct result. Bob | |||
|
| | #4 | ||
| On Thu, 21 Jun 2007 17:05:15 +0200, "Bob Bedford" wrote: >I've 3 tables. The first is a table of customers, the second a table of >orders and the third a table of questions. > >I've to provide a table with the customerid, the number of orders and the >number of questions. >For every order and every question I've a new record in those table. The >tables are quite huge, so I can't send the structure but basically in the 3 >tables they are the customerid number to link for. >[...] Using "virtual tables", something like: Select c.`name`, o.orders, q.questions From customer c Join ( Select customerid, count(ordersid) As orders From orders Group By customerid ) o On c.customerid = o.customerid, Join ( Select customerid, count(questionid) As questions From questions Group By customerid ) q On c.customerid = q.customerid Order By c.`name` NB: just typed it in, you will need to play with it / fix it yourself. -- Ross McKay, Toronto, NSW Australia "Let the laddie play wi the knife - he'll learn" - The Wee Book of Calvin | |||
|
| | #5 | ||
| > Using "virtual tables", something like: > > Select c.`name`, o.orders, q.questions > From customer c > Join ( > Select customerid, count(ordersid) As orders > From orders > Group By customerid > ) o On c.customerid = o.customerid, > Join ( > Select customerid, count(questionid) As questions > From questions > Group By customerid > ) q On c.customerid = q.customerid > Order By c.`name` > > NB: just typed it in, you will need to play with it / fix it yourself. > -- > Ross McKay, Toronto, NSW Australia > "Let the laddie play wi the knife - he'll learn" > - The Wee Book of Calvin Splendid Mate ;-) !!! works fine. Thanks a lot ! | |||
|
| Featured Websites | ||||
|
![]() |
| Tags: count, union |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| count | Andy Hassall | PHP | 0 | 07-01-2007 5:30 PM |
| I can count | scoopex | Console Subjects | 2 | 06-11-2007 1:01 AM |
| union in from clause | clifden | Database | 4 | 05-31-2007 8:45 PM |
| Western Union Payment | ukiharappa | Ebay Technical Questions | 8 | 05-31-2007 1:09 AM |
| Western Union Scam | Mike Cook | Ebay Technical Questions | 3 | 05-30-2007 2:10 AM |
| Featured Websites | ||||
|