kk Blog —— 通用基础


date [-d @int|str] [+%s|"+%F %T"]
netstat -ltunp
sar -n DEV 1

mysql 分组后的组内排序

方法一

https://www.cnblogs.com/hxfcodelife/p/10226934.html

数据库的查询顺序是先分组的,最后才将结果进行排序。 group by XX order by yy 是不行的

用 row_number() over(partition by XX order by YY desc)

1
select a.Classid,a.English from (select Classid,English,row_number() over(partition by Classid order by English desc) as n from CJ) a where n<=2

方法二

https://blog.csdn.net/u014508939/article/details/100561133

用 GROUP_CONCAT, SUBSTRING_INDEX

1
SELECT SUBSTRING_INDEX(GROUP_CONCAT(id, ORDER BY update_time DESC), ',', 1) FROM goods GROUP BY good_id OEDER by update_time DESC;

python读写dbf数据库

1
2
pip install dbfread
pip install dbfpy

https://www.cnblogs.com/zhugaopeng/p/9745800.html

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
#coding:utf-8
import dbfread
from dbfpy import dbf
import itertools
import xlrd
import sys

def writeBmh(datas, filename, header):
	db = dbf.Dbf(filename, new=True)
	for kv in header:
		# field = field.encode('GBK')
		db.addField(kv)

	idx = dict()
	n = 0
	for field in datas[0]:
		idx[field] = n
		n  = n + 1

	for record in datas:
		if record[0] == 'bmh':
			continue

		rec = db.newRecord()
		for kv in header:
			value = record[idx[kv[0]]]
			#value = value.encode('utf-8')
			#print value, type(value)
			#if type(value) == unicode:
			if kv[1] == 'D':
				value = value.replace('-', '')
			elif kv[1] == 'C':
				rec[kv[0]] = value.encode('GBK')
			elif kv[1] == 'N':
				rec[kv[0]] = int(value)
			else:
				rec[kv[0]] = value
		rec.store()
	db.close()


def readxls(filename):
	data = xlrd.open_workbook(filename)
	table = data.sheet_by_index(0)
	datas = []

	for rn in range(table.nrows):
		datas.append(table.row_values(rn))

	return datas

f1='mm.xlsx'
datas = readxls(f1)
h=[['bmh','C',10],['bmm','C',76],['oldbmh','C',10],['bm','C',30],['bz','C',50]]
o='m.dbf'
writeBmh(datas,o,h)