Required Query for Counting
DBAsupport.com Forums - Powered by vBulletin
Results 1 to 2 of 2

Thread: Required Query for Counting

  1. #1
    Join Date
    Dec 2006
    Location
    hyderabad
    Posts
    21

    Required Query for Counting

    Hello Experts, DAVEY23UK,

    Required Query for Count

    I was struck up with writing a query my scenario is ...

    Customer details table :
    Cno,Cname, ....... (fields)

    Product details table :
    Pno,pname .....Cno (fields where Cno refers to cno of customer)

    Cheques details table :
    chqno, .....(Cno) (fields where Cno refers to cno of customer)

    there is no direct relation or bependency between product and cheques table.

    I need to write a single query "without nesting" we can have union, such that the output is like this :

    Cno products cheques
    2...........13...........5
    5...........2............89
    9...........11...........2


    which mean it should display customer number, his purchase of total number of products, his total number of cheques issued..

    somebody help me with this, I was struck up in my work with this

    Thanks in advance,
    Regards,
    Sai.k.k.
    Last edited by girirajdba; 05-26-2007 at 04:59 AM.

  2. #2
    Join Date
    Nov 2006
    Location
    Sofia
    Posts
    630
    select c.cno customer,count(distinct p.pno) products,count(distinct ch.chno)
    from customers c,products p,cheques ch
    where c.cno=p.cno and c.cno=ch.cno
    group by c.cno

    PLEASE TEST CAREFULL!!! Not sure if it is exactly what u need

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width