 |
|
ถ้าเราจะทำเป็นแบบ MAX แบบมีหลายสาขาเราควรทำเเบบใหนครับ สมุติ สาขาที่ 1 Max เป็น 1005 เเล้ว ถ้าสาขาที่ 2 มาเริ่ม max เริ่ม 1ใหม่ครับ |
|
 |
|
|
 |
 |
|
คำถามไม่เคลียร์
|
 |
 |
 |
 |
Date :
2017-10-27 09:55:45 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ประมาณนี้ะครับ NAME คือสาขา VALUE คือค่า MAX
Code (SQL)
SELECT MAX(VALUE),NAME FROM TEMP_TABLE GROUP BY NAME
|
 |
 |
 |
 |
Date :
2017-10-27 10:07:22 |
By :
OOP |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<?php
$db=new mysqli('host', 'test','test','test');
if($db->connect_error){
die($db->connect_error);
}
$branch_id='a';
$sql="
insert into test (branch_id, run_no, other_fld1, other_fld2)
select
branch_id, max(run_no)+1, 1, 2
from test
where branch_id = '$branch_id'
group by branch_id;
select max(run_no) as new_insert from test where branch_id='$branch_id';
";
if($db->multi_query($sql) or die($db->error)){
$rs=array();
do{
$rs[]=$db->store_result();
}while($db->next_result());
$ro=end($rs)->fetch_assoc();
echo $new_insert=$ro['new_insert'];
}
|
 |
 |
 |
 |
Date :
2017-10-30 11:30:29 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อาจจะต้องแปลงนิดหน่อย อาจจะต้องเขียนเป็น stroeprocedure
database เป็นอะไรครับ mysql หรือ sqlserver หรือ access
ตัวอย่างอย่างง่ายๆ
Code (VB.NET)
sql = "multi statement จากตัวอย่างด้านบน"
MySqlCommand COMMAND = New MySqlCommand(sql, MysqlConn)
dataReader = command.ExecuteReader();
|
ประวัติการแก้ไข 2017-10-30 15:46:26
 |
 |
 |
 |
Date :
2017-10-30 15:39:14 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|