比如说, 有三列 a,b,c查询完后,在表前或者表后添加根据某一列统计出的值。比如:a    b   c   
-----------
sd   fd  2
df   as  3
qw    re 5
hg    qw 6
df   we  9
-----
a=4 

解决方案 »

  1.   

    比如根据某个条件,查出了一堆数据,
    现在我需要知道一共有多少行被查询出来。
    现在我是一个一个数多少行,当然可以在studio能直接看出,
    但是我想直接添加一行,显示查询出来的行数。
    谢谢
      

  2.   

    select * from xx where yy=123
    union all
    select count(*),null,null from xx where yy=123
      

  3.   

    建议你列出你的表结构,并提供测试数据以及基于这些测试数据的所对应正确结果。
       参考一下这个贴子的提问方式http://topic.csdn.net/u/20091130/20/8343ee6a-417c-4c2d-9415-fa46604a00cf.html
       
       1. 你的 create table xxx .. 语句
       2. 你的 insert into xxx ... 语句
       3. 结果是什么样,(并给以简单的算法描述)
       4. 你用的数据库名称和版本(经常有人在MS SQL server版问 MySQL)
       
       这样想帮你的人可以直接搭建和你相同的环境,并在给出方案前进行测试。   
      

  4.   

    select IP_address,caption
    from dbo.Nodes
    where caption like '%DOM%'
    这是下面的表
    IP_address      Caption
    10.102.0.29 DOM - Makarenko
    10.102.0.51 DOM - Morro da Luz
    10.102.0.20 DOM - Cacuaco 
    10.102.0.61 DOM - Sambizanga
    10.102.0.1 DOM - Alvalade 
    10.102.0.10 DOM - Kinaxixe 想得到这样的表:
    IP_address      Caption
    10.102.0.29 DOM - Makarenko
    10.102.0.51 DOM - Morro da Luz
    10.102.0.20 DOM - Cacuaco 
    10.102.0.61 DOM - Sambizanga
    10.102.0.1 DOM - Alvalade 
    10.102.0.10 DOM - Kinaxixe 
    -----------------
    DOM Total = 6不知道这样清楚没?谢谢楼上的。
      

  5.   

    select IP_address,caption
    from dbo.Nodes
    where caption like '%DOM%'
    select count(caption) from nodes
    where caption like '%DOM%'这样显示出来的结果是分开的,类似两张表,如何能合到一起?
      

  6.   

    select IP_address,caption 
    from dbo.Nodes 
    where caption like '%DOM%' 
    union all
    select 'DOM','Total ='+ltrim(count(1)) from nodes 
    where caption like '%DOM%'
      

  7.   

    select IP_address,caption
    from dbo.Nodes
    where caption like '%DOM%'
    union all
    select 'Total=',count(caption) from nodes
    where caption like '%DOM%'
      

  8.   

    select IP_address,caption 
    from dbo.Nodes 
    where caption like '%DOM%' 
    union all
    select 'DOM','Total ='+ltrim(count(1)) from nodes 
    where caption like '%DOM%'
      

  9.   

    楼上的,为什么这里要用  ltrim 函数?去掉左边空白的部分?不懂,请指教!