그래서 내가 잘 작동이 문을 얻었다. 그래서그룹 SQL 문에 의해
SELECT MAX(patient_history_date_bio) AS med_date, medication_name, medication_dose
FROM biological
WHERE (patient_id = 12)
GROUP BY medication_name
을이를 입력, 그것은 말을 나에게 오류를 제공합니다
"coumn 'biological.medication_dose' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.".
그래서 내가 GROUP BY 절에 medication_dose를 추가하려고하지만, 그것은 나에게 내가 '돈 여분의 행을 제공합니다 싶어. 테이블에있는 각 약물에 대한 최신 행을 가져오고 싶습니다. (최신 행은 max 함수에 의해 결정되어 최신 날짜를 얻습니다).
이 문제를 어떻게 해결합니까?
그것은 OP는 보이는 것처럼를 SQL Server를 사용합니다. –
Visual Studio 2008에서 C#으로 코딩하는 데 사용되는 코드입니다. 나는 그것이 바로 SQL 서버라고 생각하니? – jello
참고 사항 : http://stackoverflow.com/questions/121387/sql-fetch-the-row-which-has-the-max-value-for-a-column, http://stackoverflow.com/questions/ 95866/select-max-in-group, http://stackoverflow.com/questions/612231/sql-selectrows-with-maxcolumn-value-distinct-by-another-column 및 기타 여러 가지가 있습니다. – outis