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 14:52:23 浏览: 63
您可以在查询数据后再添加一行汇总信息,计算每个员工当日总工资的总和,并将其添加到表格的最后一行,代码示例如下:
```python
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
# 计算总工资汇总信息
total_salary = sum([row[-1] for row in result])
summary_row = ['汇总', '', '', '', '', '', '', '', total_salary]
result.append(summary_row)
# 清空表格
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()
```
阅读全文