insert into 表
select a.id as autoid,b.km,a.id as month,b.je from
(
select 1 id union all
select 2 union all
select 3 union all
select 4 union all
select 5 union all
select 6 union all
select 7 union all
select 8 union all
select 9 union all
select 10 union all
select 11 union all
select 12
) a,表 b where not exists
(select 1 from 表 where autoid=a.id)
结果要求:autoid km mouth je
自动编号 科目 月份 金额
1 101 1 100.00
2 101 2 100.00
3 101 3 100.00
4 101 4 100.00
5 101 5 100.00
6 101 6 100.00
7 101 7 100.00
8 101 8 100.00
9 101 9 100.00
10 101 10 100.00
11 101 11 100.00
12 101 12 100.00
13 10101 1 50.00
14 10101 2 50.00
15 10101 3 50.00
16 10101 4 50.00
17 10101 5 50.00
18 10101 6 50.00
19 10101 7 50.00
20 10101 8 50.00
21 10101 9 50.00
22 10101 10 50.00
23 10101 11 50.00
24 10101 12 50.00
25 10102 1 50.00
26 10102 2 50.00
27 10102 3 50.00
28 10102 4 50.00
29 10102 5 50.00
30 10102 6 50.00
31 10102 7 50.00
32 10102 8 50.00
33 10102 9 50.00
34 10102 10 50.00
35 10102 11 50.00
36 10102 12 50.00不知道这样写会不会明白。
insert into 表(km,month,je)
select km,month,je from (
select b.km,a.id as month,b.je from (
select 1 id union all
select 2 union all
select 3 union all
select 4 union all
select 5 union all
select 6 union all
select 7 union all
select 8 union all
select 9 union all
select 10 union all
select 11 union all
select 12 ) a ,表 b
) a where
not exists (select 1 from 表 where km=a.km and month=a.month)