Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,028

HOME > PHP > PHP Forum > ต้องการดึงข้อมูลใน MySQL ซึ่งมีเงื่อนไขคือหาผลรวมที่มีค่ามากที่สุด 4 Record



 

ต้องการดึงข้อมูลใน MySQL ซึ่งมีเงื่อนไขคือหาผลรวมที่มีค่ามากที่สุด 4 Record

 



Topic : 079432



โพสกระทู้ ( 63 )
บทความ ( 0 )



สถานะออฟไลน์




คือผมต้องการแสดงคะแนนการแข่งกีฬา ซึ่งเด็กแต่ละคนจะแข่งหลายชนิดกีฬา
ความต้องการของผมก็คือ หาผลรวมที่มากที่สุด 4 ชนิดกีฬาของเด็กคนนั้น

อันนี้เป็นตัวอย่างที่ผมเขียน แต่มันไม่ได้ครับ ตอนที่มัน SUM มันจะ SUM ทั้งหมดเลย

Code
select distinct(tr.s_code),s_fname,s_lname,(select sum(point) as sum_point from time_result as trs where trs.s_code=tr.s_code order by trs.point DESC limit 4) as total from time_result as tr inner join student_fobissea as sf on (tr.s_code=sf.s_code)
where 1 and tr.s_year in ($s_year) and tr.s_gender='$sc_gender' order by total DESC



รบกวนพี่ๆช่วยดูให้หน่อยนะครับ
ขอบคุณล่วงหน้าครับผม



Tag : PHP, MySQL







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2012-06-06 15:03:09 By : sober View : 1096 Reply : 4
 

 

No. 1



โพสกระทู้ ( 937 )
บทความ ( 2 )



สถานะออฟไลน์
Facebook

สร้างDBไว้ยังไงค่ะ จะได้เขียนถูกค่ะ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-06-06 16:22:08 By : LuckyStar
 


 

No. 2



โพสกระทู้ ( 63 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 1 เขียนโดย : LuckyStar เมื่อวันที่ 2012-06-06 16:22:08
รายละเอียดของการตอบ ::
ประมาณว่า SUM TOP 4 อ่ะครับ

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-06-06 21:36:49 By : sober
 

 

No. 3



โพสกระทู้ ( 63 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 1 เขียนโดย : LuckyStar เมื่อวันที่ 2012-06-06 16:22:08
รายละเอียดของการตอบ ::
no s_code s_gender s_year s_house sp_id point
1 156 Male 5 HIS 4 13
2 46 Male 5 BISP 4 12
3 7 Male 5 BISJ 3 11
4 81 Male 5 BPS 4 10
5 116 Male 5 GIS 4 9
6 48 Male 5 BISP 3 7
7 79 Male 5 BPS 3 5
8 226 Male 5 SHB 4 4
9 151 Male 5 HIS 3 3
10 262 Male 5 TTS 4 2
11 117 Male 5 GIS 3 1
12 261 Male 5 TTS 3 0
13 187 Male 5 KLASS 4 0
14 224 Male 5 SHB 3 0
15 189 Male 5 KLASS 3 0
16 189 Male 5 KLASS 4 10
17 7 Male 5 BISJ 10 8
17 7 Male 5 BISJ 11 2

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-06-07 08:02:35 By : sober
 


 

No. 4

Guest


น่าจะประมาณนี้ครับ ลองไปแก้ไขดูครับ


select s_code,s_fname,s_lname,		
((select point from time_result as tr where tr.s_code=trs.s_code order by point desc limit 0,1)
+(select point from time_result as tr where tr.s_code=trs.s_code order by point desc limit 1,1)
+(select point from time_result as tr where tr.s_code=trs.s_code order by point desc limit 2,1)
+(select point from time_result as tr where tr.s_code=trs.s_code order by point desc limit 3,1))as total
from student_fobissea as trs 
where  tr.s_year in ($s_year) and tr.s_gender='$sc_gender' order by total DESC

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-06-07 19:12:22 By : ผ่านมา
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ต้องการดึงข้อมูลใน MySQL ซึ่งมีเงื่อนไขคือหาผลรวมที่มีค่ามากที่สุด 4 Record
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 00
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่