大家好!
我通过以下查询语句:use stock
select 安徽风之星 from store where 安徽风之星 is not null
union all
select 甘肃地区 from store where 甘肃地区 is not null
union all
select 广西机电 from store where 广西机电 is not null
union all
select 河北华安 from store where 河北华安 is not null
union all
select 河南裕华 from store where 河南裕华 is not null
union all
select 山东翔宇 from store where 山东翔宇 is not null
union all
select 陕西地区 from store where 陕西地区 is not null
union all
select 新疆天汇 from store where 新疆天汇 is not null
union all
select 中汽西南 from store where 中汽西南 is not null
except 
select 专卖店 from result where 专卖店 is not null and 月份 = '8'
得到一列数据,列名为:安徽风之星,我想问下,再怎么加语句,来查询出结果有多少记录呢?
只用返回记录的条数即可。谢谢热心的您回答我的问题

解决方案 »

  1.   

    use stock
    select count(*) from 
    (select 安徽风之星 from store where 安徽风之星 is not null
    union all
    select 甘肃地区 from store where 甘肃地区 is not null
    union all
    select 广西机电 from store where 广西机电 is not null
    union all
    select 河北华安 from store where 河北华安 is not null
    union all
    select 河南裕华 from store where 河南裕华 is not null
    union all
    select 山东翔宇 from store where 山东翔宇 is not null
    union all
    select 陕西地区 from store where 陕西地区 is not null
    union all
    select 新疆天汇 from store where 新疆天汇 is not null
    union all
    select 中汽西南 from store where 中汽西南 is not null
    except 
    select 专卖店 from result where 专卖店 is not null and 月份 = '8') as a
    这样?
      

  2.   

    谢谢您的回答!
    多嘴问一句,最后一句as a 何解?
    虽然得到了记录的条数,可是列名消失了。。不知道为什么
      

  3.   

    use stock
    select count(1) 你想要的列名 from
    (
    select 安徽风之星 from store where 安徽风之星 is not null
    union all
    select 甘肃地区 from store where 甘肃地区 is not null
    union all
    select 广西机电 from store where 广西机电 is not null
    union all
    select 河北华安 from store where 河北华安 is not null
    union all
    select 河南裕华 from store where 河南裕华 is not null
    union all
    select 山东翔宇 from store where 山东翔宇 is not null
    union all
    select 陕西地区 from store where 陕西地区 is not null
    union all
    select 新疆天汇 from store where 新疆天汇 is not null
    union all
    select 中汽西南 from store where 中汽西南 is not null
    except 
    select 专卖店 from result where 专卖店 is not null and 月份 = '8'
    ) tt--别名