 |
|
รบกวนช่วยหน่อยค่ะ เรื่อง หาผลรวมข้อมูล (sum) ค่ะ |
|
 |
|
|
 |
 |
|
ใช้ Group by สิครับ
Code (SQL)
SELECT EMPLOYEE.MEMP , EMPLOYEE.MPNAME + CHAR(9) + EMPLOYEE.MFNAME + CHAR(9) AS NAME , EMPLOYEE.MFLASTNAME, Min(Interest.MINTEREST)
FROM Interest INNER JOIN EMPLOYEE ON EMPLOYEE.MEMP = Interest.MEMP
INNER JOIN EMPLOYEEDT ON EMPLOYEE.MEMP = EMPLOYEEDT.MEMP
WHERE Interest.YEAR = '2557'
Group by EMPLOYEE.MEMP , EMPLOYEE.MPNAME + CHAR(9) + EMPLOYEE.MFNAME + CHAR(9) AS NAME , EMPLOYEE.MFLASTNAME
ORDER BY EMPLOYEE.MEMP ;
หรือใช้ subselect min
Code (SQL)
SELECT EMPLOYEE.MEMP , EMPLOYEE.MPNAME + CHAR(9) + EMPLOYEE.MFNAME + CHAR(9) AS NAME , EMPLOYEE.MFLASTNAME, (Select Min(Interest.MINTEREST) From Interest Where EMPLOYEE.MEMP = Interest.MEMP) MINTEREST
FROM EMPLOYEE INNER JOIN EMPLOYEEDT ON EMPLOYEE.MEMP = EMPLOYEEDT.MEMP
WHERE Interest.YEAR = '2557'
ORDER BY EMPLOYEE.MEMP ;
|
 |
 |
 |
 |
Date :
2014-05-20 10:11:28 |
By :
deksoke |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ใช่แบบที่ต้องการหรือเปล่า
Code (SQL)
SELECT MEMP ,SUM(MINTEREST) MINTEREST
FROM Interest
WHERE (MEMP = 9)
GROUP BY MEMP
|
 |
 |
 |
 |
Date :
2014-05-20 10:57:39 |
By :
Agility |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แบบนี้ไหมอะครับ ไม่รู้เออเร่อปล่าว ไม่ได้ลองใน SQLSERVER
Code (SQL)
SELECT EMPLOYEE.MEMP ,
EMPLOYEE.MPNAME + CHAR(9) + EMPLOYEE.MFNAME + CHAR(9) AS NAME ,
EMPLOYEE.MFLASTNAME,
EmployeeDT.SAVINGDEP , Interest.MINTEREST ,EmployeeDT .FUND
,
SUM(Interest.MINTEREST) AS SUM_MINTEREST
FROM Interest
INNER JOIN EMPLOYEE ON EMPLOYEE.MEMP = Interest.MEMP
INNER JOIN EMPLOYEEDT ON EMPLOYEE.MEMP = EMPLOYEEDT.MEMP
WHERE Interest.YEAR = '2557'
GROUP BY EMPLOYEE.MEMP,
EMPLOYEE.MPNAME + CHAR(9) + EMPLOYEE.MFNAME + CHAR(9), EMPLOYEE.MFLASTNAME,
EmployeeDT.SAVINGDEP , Interest.MINTEREST ,EmployeeDT .FUND
ORDER BY EMPLOYEE.MEMP ;
|
 |
 |
 |
 |
Date :
2014-05-20 11:02:25 |
By :
CPU4Core |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ได้แล้วค่ะ ขอบคุณพี่ๆมากๆค่ะ
โค๊ด sql แบบนี้ค่ะ
Code (SQL)
SELECT EMPLOYEE.MEMP , EMPLOYEE.MPNAME + CHAR(9) + EMPLOYEE.MFNAME + CHAR(9) AS NAME , EMPLOYEE.MFLASTNAME, EmployeeDT .SAVINGDEP , EmployeeDT .FUND ,SUM(Interest.MINTEREST)
FROM Interest INNER JOIN EMPLOYEE ON EMPLOYEE.MEMP = Interest.MEMP
INNER JOIN EMPLOYEEDT ON EMPLOYEE.MEMP = EMPLOYEEDT.MEMP
WHERE Interest.YEAR = '2557'
Group by EMPLOYEE.MEMP , EMPLOYEE.MPNAME , EMPLOYEE.MFNAME , EMPLOYEE.MFLASTNAME ,EmployeeDT .SAVINGDEP , EmployeeDT .FUND
ORDER BY EMPLOYEE.MEMP ;
|
 |
 |
 |
 |
Date :
2014-05-21 09:33:19 |
By :
chariyamat |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|