由于我不会C#和java,所以我就用其他的程序写了一个。
第一个问题,一句SQL语句执行即可成功获得。
'select 身份证号,max(来自城市) as 来自城市,max(进入时间) as 最近来访时间,count(车次) as 来访次数 from 来访者登记表 group by 身份证号';
第二个问题,关于时间:
由于数据库存在的是text,
设定数据库存在的是date,取出说有的数字然后存为tmpdate,
A,判断数字个数,如果是8,
insert('/', tmpdate, 5);
insert('/', tmpdate, 8);
date:=tmpdate;
B,判断数字个数,如果是6,并且第一个数字是0或则9,不是1和2的情况。
即时间格式
{091025=09/10/25(包括)
031025=03/10/25(包括)
199121=1991/2/1(不包括)date转C
200325=2003/2/5(不包括) date转C
}
insert('/', tmpdate, 3);
insert('/', tmpdate, 6);
date:=tmpdate;
C,如果不是8和6,哪么把date中的所有非数字进行替换'/',
最后再对'//'进行替换,得到最终的date。
这样所有的95%和5%都包括进去了。
所有的需要两个,一个是if判断,一个是case choice of 选择。
if count(tmpdate) =8 then
choice =8 else
if (((length(tmp) = 6) and (tmp[1] <> '1') and (tmp[1] <> '2')) then choice =6 else if choice =7;
case choice of
8:............
6:............
7: ...........
下面贴出delphi代码。
1,处理时间函数
function transdate(str: string): string;
function DelOthreExceptNum(str: string): string;
var
i: integer;
begin
result := '';
for i := 1 to length(str) do
if (str[i] >= '0') and (str[i] <= '9') then
result := result + str[i];
end;
var
i: integer;
tmp, s: string;
choice: integer;
begin
result := '';
str := trim(str);
tmp := DelOthreExceptNum(str);
if length(tmp) = 8 then
choice := 8
else if ((length(tmp) = 6) and (tmp[1] <> '1') and (tmp[1] <> '2')) then
choice := 6
else
choice := 7;
case choice of
8:
begin
insert('/', tmp, 5);
insert('/', tmp, 8);
str := tmp;
end;
6:
begin
insert('/', tmp, 3);
insert('/', tmp, 6);
str := '20'+tmp;//因为确定为SARS期间,所以这里就可以加上20。
end;
else
begin
for i := length(str) downto 1 do
if not (str[i] >= '0') and (str[i] <= '9') then
str[i] := '/';
end;
end;
str := stringreplace(str, '//', '/', [rfreplaceall]);
result := str;
end;
2,备份函数
procedure TForm1.Button1Click(Sender: TObject);
var
i, j, posdate: integer;
strlist: tstringlist;
str, tmp, s: string;
begin
posdate := 0;
adoquery1.SQL.Clear;
adoquery1.SQL.Text :=
'select 身份证号,max(来自城市) as 来自城市,max(进入时间) as 最近来访时间,count(车次) as 来访次数 from 来访者登记表 group by 身份证号';
adoquery1.Open;
strlist := tstringlist.Create;
adoquery1.GetFieldNames(strlist);
str := '';
for i := 0 to strlist.Count - 1 do
begin
str := str + strlist.Strings[i] + ',';
if pos('时间', strlist.Strings[i]) > 0 then
posdate := i;
end;
strlist.Clear;
if posdate > 0 then
begin
strlist.Add(str);
adoquery1.First;
for j := 0 to adoquery1.RecordCount - 1 do
begin
str := '';
for i := 0 to adoquery1.FieldCount - 1 do
begin
tmp := adoquery1.Fields[i].AsString;
if i = posdate then
s := trim(transdate(tmp))
else
s := tmp;
str := str + s + ',';
end;
strlist.Add(str);
adoquery1.Next;
end;
strlist.SaveToFile('bak.csv');
strlist.Free;
end;
end;
分给我吧,就算程序看不懂,但是前边的一个SQL语句,和一个时间的转换思路,就值了。