question about conut in sql

  • hello,

    i have one question thanks for answering

    select conut(*) as type

    from tblname

    where group=a

    union all

    select conut(*) as type

    from tblname

    where group=b

    Result

    15

    20

    but i want Result diplay like

    type | group

    15 a

    20 | b

  • I assume you mean Count...

    select COUNT(*) as [type], [group]

    from tblname

    where group in ('a','b')

    Group by [group]

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • thanks GilaMonster, its correct

    select COUNT(*) as [type], [group]

    from tblname

    where group in ('a','b')

    Group by [group]

    but haw use

    where group in ('%a%','%b%')

    i can use it

  • bbf.kurd (5/20/2014)


    thanks GilaMonster, its correct

    select COUNT(*) as [type], [group]

    from tblname

    where group in ('a','b')

    Group by [group]

    but haw use

    where group in ('%a%','%b%')

    i can use it

    WHERE [group] LIKE '%a%' OR [group] LIKE '%b%'

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply