日期:2014-05-18  浏览次数:20920 次

求一条SQL 语句 , 简单的,写出给10分。关于合并2条SQL语句
select   count(jobno)   as   vcount   from   tblmsjg   where   msjg= '录用 '   and   intime   between   '2007-07-1 '   and   '2007-09-01 '
====================
查询结果       (只有一行)

vcount
--------
0                          

计算   7月-9月   期间     推荐成功的人数。

我想这样,客户自定     7月,8月...   2个月,2个推荐成功的人数。
意思就是,这是做一个推荐成功率的统计功能,能够让客户用的好,应该可以同时显示相邻几个月的柱状图,这样效果比较好

我就想到了。

select   '7月 '   as   months,   count(jobno)   as   vcount   from   tblmsjg   where   msjg= '录用 '   and   intime   between   '2007-07-1 '   and   '2007-08-01 ';
select   '8月 '   as   months,   count(jobno)   as   vcount   from   tblmsjg   where   msjg= '录用 '   and   intime   between   '2007-08-1 '   and   '2007-09-01 '


查询结果变成了2个,现在请教如何把这两条查询语句的结果合并在一起~
还有,我可能不一定是2个月,有可能3个月,4个月,由客户自己定
我sql比较垃圾,各位不要见笑

------解决方案--------------------
select '7月 ' as months, count(jobno) as vcount from tblmsjg where msjg= '录用 ' and intime between '2007-07-1 ' and '2007-08-01 '
union all
select '8月 ' as months, count(jobno) as vcount from tblmsjg where msjg= '录用 ' and intime between '2007-08-1 ' and '2007-09-01 '
------解决方案--------------------
select datepart(mm,intime) as months,count(jobno) as vcount from tblmsjg where msjg= '录用 ' group by datepart(mm,intime)
------解决方案--------------------
select '7月 ' as months, count(jobno) as vcount from tblmsjg where msjg= '录用 ' and intime between '2007-07-1 ' and '2007-08-01 '
union
select '8月 ' as months, count(jobno) as vcount from tblmsjg where msjg= '录用 ' and intime between '2007-08-1 ' and '2007-09-01 '

两句中间加union
------解决方案--------------------
select '7月 ' as months, count(jobno) as vcount from tblmsjg where msjg= '录用 ' and intime between '2007-07-1 ' and '2007-08-01 '
union all
select '8月 ' as months, count(jobno) as vcount from tblmsjg where msjg= '录用 ' and intime between '2007-08-1 ' and '2007-09-01 '

------解决方案--------------------

select DATEname(year,crdate)+ '年 '+DATEname(month,crdate)+ '月 ' as months,count(name) as vcount from 表 group by DATEname(year,crdate)+ '年 '+DATEname(month,crdate)+ '月 '
------解决方案--------------------
months vcount
---------------------------- -----------
2000年08月 21
2007年07月 53
2007年08月 11
------解决方案--------------------
select DATEname(year,crdate)+ '年 '+DATEname(month,crdate)+ '月 ' as months,count(name) as vcount from sysobjects
where crdate between '2007-07-01 ' and '2007-08-31 '