def show_query1_result(self): # 查询数据 db = pymysql.connect(host='39.99.214.172', user='root', password='Solotion.123', db='jj_tset') cursor = db.cursor() db_sql = """ SELECT *,salary + weight_reward total_salary from ( SELECT a.user_id,user_name,get_time,get_kg,efficiency,CONCAT(ROUND(ROUND(yield_rate,4) * 100,2),'%') yield_rate,ROUND(get_kg * 2 * price,1) salary,CASE WHEN yield_rate > 0.64 and get_kg < 40 THEN kg1_price WHEN yield_rate > 0.64 and get_kg < 50 THEN kg2_price WHEN yield_rate > 0.64 and get_kg >= 50 THEN kg3_price WHEN yield_rate < 0.64 THEN 0 END as weight_reward FROM (SELECT user_id, DATE_FORMAT(get_time,'%Y-%m-%d') get_time, SUM(get_kg) get_kg,round(SUM(get_kg)/(SUM(duration_time)/3600),2) efficiency,AVG(yield_rate) yield_rate FROM em_salary WHERE DATE_FORMAT(get_time,'%Y-%m-%d') = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 0 DAY),'%Y-%m-%d') and recycle_kg IS NOT NULL GROUP BY user_id, DATE_FORMAT(get_time,'%Y-%m-%d')) a LEFT JOIN (SELECT user_id,name as user_name,price,kg1_price,kg2_price,kg3_price,yield_price FROM employee_table CROSS JOIN price_data ) d on a.user_id = d.user_id ) T """ cursor.execute(db_sql) result = cursor.fetchall() db.close() if len(result) == 0: QMessageBox.information(self, "提示", "今日无员工工资记录") return # 清空表格 self.query1_window.table_widget.setRowCount(0) self.query1_window.table_widget.setColumnCount(len(result[0])) self.query1_window.table_widget.setHorizontalHeaderLabels( ["员工ID", "员工姓名", "日期", "领取鸡爪重量(KG)", "效率(每小时KG)", "出成率", "基础工资", "重量奖励", "当日总工资"]) # 添加数据到表格 for row_num, row_data in enumerate(result): self.query1_window.table_widget.insertRow(row_num) for col_num, col_data in enumerate(row_data): self.query1_window.table_widget.setItem(row_num, col_num, QTableWidgetItem(str(col_data))) # 显示窗口 self.query1_window.show()能不能在最后一列显示当日总工资汇总
时间: 2023-11-27 22:52:17 浏览: 138
可以在最后一列添加当日总工资汇总,你可以在添加数据到表格的循环中,计算当日总工资并将其添加到最后一列中,类似这样:
```
# 添加数据到表格
for row_num, row_data in enumerate(result):
self.query1_window.table_widget.insertRow(row_num)
total_salary = row_data[-1] # 获取当前行的当日总工资
for col_num, col_data in enumerate(row_data):
if col_num == len(row_data)-1:
self.query1_window.table_widget.setItem(row_num, col_num, QTableWidgetItem(str(total_salary))) # 将当日总工资添加到最后一列
else:
self.query1_window.table_widget.setItem(row_num, col_num, QTableWidgetItem(str(col_data)))
```
这里假设当日总工资是结果集中的最后一列。如果不是,你需要修改代码中的 `len(row_data)-1` 为对应的列索引。
相关问题
def show_query1_result(self): # 查询数据 db = pymysql.connect(host='39.99.214.172', user='root', password='Solotion.123', db='jj_tset') cursor = db.cursor() db_sql = """ """ cursor.execute(db_sql) result = cursor.fetchall() db.close() # 清空表格 self.query1_window.table_widget.setRowCount(0) self.query1_window.table_widget.setColumnCount(len(result[0])) # 添加数据到表格 for row_num, row_data in enumerate(result): self.query1_window.table_widget.insertRow(row_num) for col_num, col_data in enumerate(row_data): self.query1_window.table_widget.setItem(row_num, col_num, QTableWidgetItem(str(col_data))) # 显示窗口 self.query1_window.show()这里怎么更改表格列名
你可以通过以下方式更改表格列名:
1. 在创建表格时设置列名:
```
self.table_widget.setColumnCount(3)
self.table_widget.setHorizontalHeaderLabels(['姓名', '年龄', '性别'])
```
2. 在查询数据之前,先清空表格并设置列名:
```
self.table_widget.setRowCount(0)
self.table_widget.setColumnCount(3)
self.table_widget.setHorizontalHeaderLabels(['姓名', '年龄', '性别'])
```
然后再将查询结果添加到表格中。
self.query1_window = QueryResultWindow() self.query2_window = QueryResultWindow() def show_query1_result(self): # 查询数据 db = pymysql.connect(host='39.99.214.172', user='root', password='Solotion.123', db='jj_tset') cursor = db.cursor() db_sql = """ """ cursor.execute(db_sql) result = cursor.fetchall() db.close() # 清空表格 self.query1_window.table_widget.setRowCount(0) self.query1_window.table_widget.setColumnCount(len(result[0])) # 添加数据到表格 for row_num, row_data in enumerate(result): self.query1_window.table_widget.insertRow(row_num) for col_num, col_data in enumerate(row_data): self.query1_window.table_widget.setItem(row_num, col_num, QTableWidgetItem(str(col_data))) # 显示窗口 self.query1_window.show()这里怎么更改表格列名
你可以在表格创建后,使用setHorizontalHeaderLabels方法来设置表格的列名。例如:
```
self.query1_window.table_widget.setColumnCount(len(result[0]))
self.query1_window.table_widget.setHorizontalHeaderLabels(["列1", "列2", "列3"])
```
其中,["列1", "列2", "列3"]是你要设置的列名列表。你可以根据你的需求修改它。
阅读全文