Professional Web Applications Themes

2 part qry - Microsoft SQL / MS SQL Server

yes, but without giving actual table structure and data i would be only guessing. here is one example on northwind database. select (select count(*) from customers) 'these are total counts of table', (select count(*) from customers where customerid ='ALFKI') 'these are counts for customerid alfki' -- -Vishal "Ben" <Benrfscliffhanger.com> wrote in message news:4d3e01c34180$52ca8810$a601280aphx.gbl... > hello, > Is it possibel for me to have a query such that I want to > return 2 values , ir, the count of entries in teh table > and the count of entries satisfying certain criteria.? > > This must be returned in teh ...

  1. #1

    Default Re: 2 part qry

    yes, but without giving actual table structure and data i would be only
    guessing.
    here is one example on northwind database.

    select (select count(*) from customers) 'these are total counts of table',
    (select count(*) from customers where customerid ='ALFKI') 'these are counts
    for customerid alfki'

    --
    -Vishal
    "Ben" <Benrfscliffhanger.com> wrote in message
    news:4d3e01c34180$52ca8810$a601280aphx.gbl...
    > hello,
    > Is it possibel for me to have a query such that I want to
    > return 2 values , ir, the count of entries in teh table
    > and the count of entries satisfying certain criteria.?
    >
    > This must be returned in teh one query.
    > Can do this?
    >
    > ALF

    Vishal Parkar Guest

  2. #2

    Default Re: 2 part qry

    Thankis Vishal, theat's what I needed.
    One more question. Say there was a third column introduced
    (such as a team). could I get the breakdown by team.
    Therefore my ouput would be :

    team,total count of that team, total count for that team
    satisfying critria.

    thanks again
    >-----Original Message-----
    >yes, but without giving actual table structure and data i
    would be only
    >guessing.
    >here is one example on northwind database.
    >
    >select (select count(*) from customers) 'these are total
    counts of table',
    >(select count(*) from customers where customerid
    ='ALFKI') 'these are counts
    >for customerid alfki'
    >
    >--
    >-Vishal
    >"Ben" <Benrfscliffhanger.com> wrote in message
    >news:4d3e01c34180$52ca8810$a601280aphx.gbl...
    >> hello,
    >> Is it possibel for me to have a query such that I want
    to
    >> return 2 values , ir, the count of entries in teh table
    >> and the count of entries satisfying certain criteria.?
    >>
    >> This must be returned in teh one query.
    >> Can do this?
    >>
    >> ALF
    >
    >
    >.
    >
    Ben Guest

  3. #3

    Default Re: 2 part qry

    select team,count(*) 'these are total counts for particular team',
    (select count(*) from table_team where team_member ='ALFKI' and team =
    a.team) 'these are counts for team member alfki'
    from table_team
    group by team a

    --
    -Vishal
    "Ben" <Benrfscliffhanger.com> wrote in message
    news:019801c34186$709aeb90$a301280aphx.gbl...
    > Thankis Vishal, theat's what I needed.
    > One more question. Say there was a third column introduced
    > (such as a team). could I get the breakdown by team.
    > Therefore my ouput would be :
    >
    > team,total count of that team, total count for that team
    > satisfying critria.
    >
    > thanks again
    >
    > >-----Original Message-----
    > >yes, but without giving actual table structure and data i
    > would be only
    > >guessing.
    > >here is one example on northwind database.
    > >
    > >select (select count(*) from customers) 'these are total
    > counts of table',
    > >(select count(*) from customers where customerid
    > ='ALFKI') 'these are counts
    > >for customerid alfki'
    > >
    > >--
    > >-Vishal
    > >"Ben" <Benrfscliffhanger.com> wrote in message
    > >news:4d3e01c34180$52ca8810$a601280aphx.gbl...
    > >> hello,
    > >> Is it possibel for me to have a query such that I want
    > to
    > >> return 2 values , ir, the count of entries in teh table
    > >> and the count of entries satisfying certain criteria.?
    > >>
    > >> This must be returned in teh one query.
    > >> Can do this?
    > >>
    > >> ALF
    > >
    > >
    > >.
    > >

    Vishal Parkar Guest

  4. #4

    Default Re: 2 part qry

    Much better performance is achieved using (CASE ... WHEN ... ELSE ... END)
    statement.

    See BOL for details.

    --
    Dean Savovic
    [url]www.teched.hr[/url]


    "Bem" <Benrfscliffhanger.com> wrote in message
    news:081601c34189$c780fc30$a001280aphx.gbl...
    > You are a lifesaver!!
    >
    > Thanks you very much..
    >
    >
    > >-----Original Message-----
    > >select team,count(*) 'these are total counts for
    > particular team',
    > >(select count(*) from table_team where team_member
    > ='ALFKI' and team =
    > >a.team) 'these are counts for team member alfki'
    > >from table_team
    > >group by team a
    > >
    > >--
    > >-Vishal
    > >"Ben" <Benrfscliffhanger.com> wrote in message
    > >news:019801c34186$709aeb90$a301280aphx.gbl...
    > >> Thankis Vishal, theat's what I needed.
    > >> One more question. Say there was a third column
    > introduced
    > >> (such as a team). could I get the breakdown by team.
    > >> Therefore my ouput would be :
    > >>
    > >> team,total count of that team, total count for that team
    > >> satisfying critria.
    > >>
    > >> thanks again
    > >>
    > >> >-----Original Message-----
    > >> >yes, but without giving actual table structure and
    > data i
    > >> would be only
    > >> >guessing.
    > >> >here is one example on northwind database.
    > >> >
    > >> >select (select count(*) from customers) 'these are
    > total
    > >> counts of table',
    > >> >(select count(*) from customers where customerid
    > >> ='ALFKI') 'these are counts
    > >> >for customerid alfki'
    > >> >
    > >> >--
    > >> >-Vishal
    > >> >"Ben" <Benrfscliffhanger.com> wrote in message
    > >> >news:4d3e01c34180$52ca8810$a601280aphx.gbl...
    > >> >> hello,
    > >> >> Is it possibel for me to have a query such that I
    > want
    > >> to
    > >> >> return 2 values , ir, the count of entries in teh
    > table
    > >> >> and the count of entries satisfying certain
    > criteria.?
    > >> >>
    > >> >> This must be returned in teh one query.
    > >> >> Can do this?
    > >> >>
    > >> >> ALF
    > >> >
    > >> >
    > >> >.
    > >> >
    > >
    > >
    > >.
    > >

    Dean Savovic Guest

Similar Threads

  1. HELP PLZ !! (part 2)
    By Aldo in forum Windows Networking
    Replies: 1
    Last Post: July 13th, 03:54 AM
  2. Getting rid of the time part
    By Vishal Parkar in forum Microsoft SQL / MS SQL Server
    Replies: 6
    Last Post: July 2nd, 06:19 PM

Bookmarks

Posting Permissions

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

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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139