1、获取数据元素
(1)获取数据元素
# Query from database A query_a = "SELECT a.id,a.name FROM LLL.test01 a WHERE a.id = 5 GROUP BY a.id" cursor_a.execute(query_a) rows_a = cursor_a.fetchall() # 获取rows_a第一组的值 first_row = rows_a[0] print("第一组数据(第一行):", first_row) # 获取第一组中的第二个元素的值 second_element = first_row[1] print("第一组中的第二个元素的值:", second_element)
(2)引用这个element
# Query from database B,使用字符串格式化操作符 %s query_b = "SELECT b.id, b.age FROM LLL02.test55 b WHERE b.id = %s" cursor_b.execute(query_b, (second_element,))
3、文件以当前时间输出
import datetime # 获取当前日期 current_date = datetime.datetime.now().strftime("%Y-%m-%d") # 原始文件名 output_file = 'CSC_Laudnrivr_.xlsx' # 添加日期到文件名中 output_file_with_date = f'CSC_Laudnrivr_{current_date}.xlsx' # 输出文件名 print(output_file_with_date)