ใน MySQL ตั้งแต่เวอร์ชั่น 8.0 เป็นต้นไป ถ้าต้องการดึงค่าแรกและค่าสุดท้ายในกรุ๊ปนั้น ๆ ออกมา สามารถใช้ Function FIRST_VALUE() FIRST_VALUE(expr) [null_treatment] over_clause Returns the value of expr from the first row of the window frame. LAST_VALUE() LAST_VALUE(expr) [null_treatment] over_clause Returns the value of expr from the last row of the window frame. ตัวอย่างการใช้งาน โจทย์ มีข้อมูล CKD Stage (สมมุติ) เรียงตามรายปีงบประมาณ ถ้าต้องการทราบ Stage แรกและสุดท้ายที่ตรวจพบในรายนั้น ๆ …
Continue reading “MySQL Get First value or Last value in each group”