1、当服务连接到数据库后重启mysql服务。
2、把链接等待超时timeout设置长一点。
以下是Oracle下的,希望对你有帮助。你的 time 在这里写出 date1,表名叫 temp_test。
1、生成某个国家的连续日期
with x as (select start_date + level-1 start_date
from (select country, min(date1) start_date, max(date1) end_date
from temp_test a
where a.country = 'usa'
group by a.country) temp
connect by level <= (end_date - start_date) + 1
) select * from x
2、过滤掉已有的日期
select start_date from (with x as (select start_date + level-1 start_date
from (select country, min(date1) start_date, max(date1) end_date
from temp_test a
where a.country = 'usa'
group by a.country) temp
connect by level <= (end_date - start_date) + 1
) select * from x ) xx
where xx.start_date not in (select date1 from temp_test a where a.country = 'usa')
3、插入。
insert into temp_test
(date1, country, people)
select start_date, 'usa', 0
from (with x as (select start_date + level - 1 start_date
from (select country,
min(date1) start_date,
max(date1) end_date
from temp_test a
where a.country = 'usa'
group by a.country) temp
connect by level <= (end_date - start_date) + 1)
select *
from x) xx
where xx.start_date not in
(select date1 from temp_test a where a.country = 'usa')
你的表格中MONAT 中并没有‘07’这个数据,所以你group by肯定是没有关于‘07’的数据的,系统没法知道你的 MONAT 就是我们常人理解的1到12个月,所以你查 A1.MONAT = '07'肯定是空。你要查这个求和如果不涉及其他应用(例如传参)的话,就用sql语句如下:
select sum(ZJ_B) from A where MONAT >'07'
如果你想前端应用就可以写个函数
CREATE function [dbo].[aGetZJ_B](@MONTH varchar(10))
returns decimal
AS
Begin
declare @sumnum decimal
Select @sumnum =sum(ZJ_B) from A where MONAT >@MONTH
return @sumnum
End
------------
然后你执行 select * from [dbo].[aGetZJ_B]('07')
* 我这个没考虑年份,你可以再加一个 year 参数
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)