BMS-HOSxP Community

HOSxP => แจ้งปัญหา / ขอความช่วยเหลือ => ข้อความที่เริ่มโดย: panus_t ที่ มกราคม 23, 2014, 11:20:46 AM

หัวข้อ: สอบถามการใช้ Group by
เริ่มหัวข้อโดย: panus_t ที่ มกราคม 23, 2014, 11:20:46 AM
สอบถามการใช้ Group by
สมมุติว่าใช้ 
1. select * from vn_stat where hn="000000339"  (87 record)
2. select * from vn_stat where hn="000000339"  group by hn จะเหลือเฉพาะ record แรก
แต่ถ้าต้องการให้เหลือ record สุดท้าย (ล่าสุด) ต้องทำไงครับ

(ไม่ใช่มี HN เดียวนะครับ คือตัวอย่างเฉย ผมจะนำไปประยุกต์ใช้ครับ)  ;D
หัวข้อ: Re: สอบถามการใช้ Group by
เริ่มหัวข้อโดย: pop_hosxp ที่ มกราคม 23, 2014, 13:12:49 PM
select * from vn_stat where hn="000000339" group by hn order by vn desc limit 1
หัวข้อ: Re: สอบถามการใช้ Group by
เริ่มหัวข้อโดย: panus_t ที่ มกราคม 23, 2014, 14:53:11 PM
select * from vn_stat where hn="000000339" group by hn order by vn desc limit 1
ถ้าอยางนี้ล่ะครับ
select vn,hn,pdx from vn_stat where vstdate between "2012-10-01" and "2013-09-30"
ต้องการ vn pdx ล่าสุด ของแต่ละ hn ในช่วงที่กำหนด ครับ