-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patht.pl
60 lines (51 loc) · 1.34 KB
/
t.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/perl
use utf8;
use strict;
use DBI;
my $dbh = DBI->connect(
"dbi:mysql:dbname=wg",
"root",
"root",
{ RaiseError => 1 },
) or die $DBI::errstr;
$dbh->do("SET character_set_client = 'utf8'");
$dbh->do("SET character_set_connection = 'utf8'");
$dbh->do("SET character_set_results= 'utf8'");
my $sth = $dbh->prepare( "select count(*) as count, name from sys_goods group by name order by count" );
$sth->execute();
my $i = 0;
while(my ($count, $name) = $sth->fetchrow())
{
if($count > 1)
{
my $sql = "select id from sys_goods where name = '$name' order by id";
#print "$sql\n";
my $sth1 = $dbh->prepare($sql);
$sth1->execute();
my $j = 0;
my $id0 = "";
my $id1 = "";
while(my ($id) = $sth1->fetchrow())
{
if($j == 0)
{
$id0 = $id;
}
if($j == 1)
{
$id1 = $id;
}
$j ++;
}
# print "$count $name: $id0, $id1\n";
# print "update store_goods set goods_id = $id1 where goods_id = $id0;\n";
# print "update store_goods set goods_id = $id0 where goods_id = $id1;\n";
print "delete from sys_goods where id = $id0;\n";
$i++;
}
}
print "i = $i\n";
my $rows = $sth->rows();
print "We have selected $rows row(s)\n";
$sth->finish();
$dbh->disconnect();