如何写一句sql语句,读取以日期命名的近三个月的数据库表中的uuid和ctime字段
问题描述:
已经写好的语句:
startdate =
tb = 'ios_log_tb_' + startdate.strftime("%Y_%m_%d");
sql = "SELECT uuid, ctime from "+ tb
这个startdate该怎么写?
答
try:
conn = MySQLdb.connect(
host = "localhost",
user = "root",
passwd = "root",
#db = "dome"
)
cur = conn.cursor()
#获取mysql中所有数据库
cur.execute('SHOW DATABASES')
print(cur.fetchall())
获取到所有表后,判断表名是否包含currency,如果包含就放到集合里面,然后遍历集合查值
答
select uuid,ctime from A union all select uuid,crime from B ……
以此类推联合多表查询。还能加入group by,order by,where 等等查询
答
select uuid,ctime from A union all select uuid,ctime