我需要将所有数量的表字段相加并获得最新的最后记录ID。
示例:
假设我们有一个表tbl_salarypaid,其字段为“paidamount”
表格中的数据
emp_id paidamount rec_added_date
1 500 2015-11-30
1 500 2015-12-31
需要获得总和(paidamount),rec_added_date类似
SELECT sum(paidamount) as total_paid, rec_added_date from tbl_salarypaid WHERE emp_id = 1
预期结果:
1000, 2015-12-31
1000 = sum of all paidamount field
2015-12-31 = latest rec_added_date
答案 0 :(得分:0)
使用max()
:
SELECT sum(paidamount) as total_paid, max(rec_added_date)
FROM tbl_salarypaid
WHERE emp_id = 1