 |
|
ช่วยดู SQL ทีครับต้องการ GROUP BY แต่ไอดี แต่มันบังคับให้ GROUP BY firstname ด้วย |
|
 |
|
|
 |
 |
|
ใช้ DISTINCT ก็น่าจะพอแล้วนะครับ
Code (SQL)
SELECT
DISTINCT
a.questionId,
a.firstname
FROM
(
SELECT q.questionId, u.firstname, u.lastname, q.createdDate FROM HR_CALLCENTER.dbo.question AS q
INNER JOIN HR_CALLCENTER.dbo.users AS u ON q.createdId = u.employeeId
UNION
SELECT r.questionId, u.firstname, u.lastname, r.createdDate FROM HR_CALLCENTER.dbo.reply AS r
INNER JOIN HR_CALLCENTER.dbo.users AS u ON r.createdId = u.employeeId
) AS a
|
 |
 |
 |
 |
Date :
2017-02-15 15:50:18 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จาก Query ทำไมถึงแสดง เวลา ด้วยครับ 
|
 |
 |
 |
 |
Date :
2017-02-15 16:57:39 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (SQL)
SELECT
DISTINCT
a.questionId,
a.firstname,
MAX(q.createdDate) AS createdDate
FROM
(
SELECT q.questionId, u.firstname, u.lastname, q.createdDate FROM HR_CALLCENTER.dbo.question AS q
INNER JOIN HR_CALLCENTER.dbo.users AS u ON q.createdId = u.employeeId
UNION
SELECT r.questionId, u.firstname, u.lastname, r.createdDate FROM HR_CALLCENTER.dbo.reply AS r
INNER JOIN HR_CALLCENTER.dbo.users AS u ON r.createdId = u.employeeId
) AS a
GROUP BY a.questionId, a.firstname
|
 |
 |
 |
 |
Date :
2017-02-16 09:21:17 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|