· 8 years ago · Feb 25, 2018, 11:24 PM
1------------------------------------------------------------------------------
2--**Drop temp_smartnodelist_full if it exists and then create
3DROP IF exists temp_smartnodelist_full
4create temp table temp_smartnodelist_full (
5txid varchar(64)
6,index int
7,status varchar(100)
8,protocol int
9,address varchar(34)
10,lastseen int
11,activeseconds int
12,lastpaidtime int
13,lastpaidblock INT
14,ip varchar(20)
15,PRIMARY KEY(address, txid)
16);
17------------------------------------------------------------------------------
18---**Merge into smartnodelist_full on address and txid and insert when exists
19MERGE into smartnodelist_full sf
20
21USING (SELECT txid
22,index
23,status
24,protocol
25,address
26,lastseen
27,activeseconds
28,lastpaidtime
29,lastpaidblock
30,ip
31 FROM temp_smartnodelist_full
32 ) AS tsf
33
34ON tsf.address = sf.address
35 and tsf.txid=sf.txid
36
37WHEN MATCHED
38 UPDATE SET --Balance = Balance - TransactionValue
39 sf.index=tsf.index
40 ,sf.status=tsf.status
41 ,sf.protocol=tsf.protocol
42 ,sf.lastseen=tsf.lastseen
43 ,sf.activeseconds=tsf.activeseconds
44 ,sf.lastpaidtime=tsf.lastpaidtime
45 ,sf.lastpaidblock=tsf.lastpaidblock
46 ,sf.ip=tsf.ip
47
48WHEN NOT MATCHED
49 INSERT (sf.txid
50,sf.index
51,sf.status
52,sf.protocol
53,sf.address
54,sf.lastseen
55,sf.activeseconds
56,sf.lastpaidtime
57,sf.lastpaidblock
58,sf.ip )
59 VALUES( tsf.txid
60,tsf.index
61,tsf.status
62,tsf.protocol
63,tsf.address
64,tsf.lastseen
65,tsf.activeseconds
66,tsf.lastpaidtime
67,tsf.lastpaidblock
68,tsf.ip
69)
70;