偶想把几个查询结果合成一个表,sql如下
select count(*) from studenttable where 户籍地 like '%大山居%' and  
union select count(*) from studenttable where 户籍地 like '%小山居%' and 
union select count(*) from studenttable where 户籍地 like '%大小山居%'和分析器测试,出错:
数据类型 bigint 对于函数 substring 无效。允许的类型为: char/varchar、nchar/nvarchar 和 binary/varbinary。请问要怎样写才对?

解决方案 »

  1.   

    select count(*) from studenttable where 户籍地 like '%大山居%' 
    union 
    select count(*) from studenttable where 户籍地 like '%小山居%'
    union 
    select count(*) from studenttable where 户籍地 like '%大小山居%'
      

  2.   

    union或者union allunion会去掉重复记录
    union all不会
      

  3.   

    提错问题了!
    select count(*) from studenttable where 户籍地 like '%大山居%' and substring(班级编号,6,2)='11'
    结果提示:
    数据类型 bigint 对于函数 substring 无效。允许的类型为: char/varchar、nchar/nvarchar 和 binary/varbinary。
    “班级编号”在数据库里是bigint型,请问要怎样写才对?
      

  4.   

    hehe,提错问题了~~
    tanxiangfeng(黑鼻子) 你真聪明