Computer Webmaster Gaming Console Graphics Forum

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.

MK PitStop Main Earn $25 Earn Money Posting Extras Members Blogs Image Hosting User Pages
Go Back   Computer Webmaster Gaming Console Graphics Forum > Webmaster Forum > Website Coding > Database
Register FAQ/Rules Become A V.I.P. Member Search Today's Posts Mark Forums Read

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.

Google
Reply
 
LinkBack Thread Tools Display Modes
Old 07-02-2007, 10:58 AM   #1
Bob Bedford
 
Bob Bedford's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default union and count

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 ?


 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
Advertisements
Old 07-02-2007, 10:58 AM   #2
patrice
 
patrice's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default union and count

"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 ?")


 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
Old 07-02-2007, 10:58 AM   #3
Bob Bedford
 
Bob Bedford's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default union and count


"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


 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
Old 07-02-2007, 10:58 AM   #4
Ross McKay
 
Ross McKay's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default union and count

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
 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
Old 07-02-2007, 10:58 AM   #5
Bob Bedford
 
Bob Bedford's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default union and count

> 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 !


 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
Featured Websites
Free Space
Free Space
Free Space Free Space
Reply
Tags: ,




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

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




All times are GMT +1. The time now is 5:20 AM.


Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.0.0
Cheap Computers
MK PitStop Copyright 2005 - 2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98