 |
สอบถามการดึงข้อมูลมาแสดงและรวมข้อมูลที่ซ้ำกันในฐานข้อมูล sql ครับ |
|
 |
|
|
 |
 |
|
select count(id) from box group by name
ได้ไหมครับไม่ได้ลองนะ
|
 |
 |
 |
 |
Date :
2018-10-02 11:05:14 |
By :
DK |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
select name,count(id) from box where date = "2018-10-01" group by name
ปรับหน่อยนืงดิเขียน condition เพิ่มเข้าไป
|
 |
 |
 |
 |
Date :
2018-10-02 16:48:32 |
By :
DK |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอบความคิดเห็นที่ : 3 เขียนโดย : DK เมื่อวันที่ 2018-10-02 16:48:32

Code (PHP)
<tr>
<td align="center" width="60">วันที่</td>
<td align="center" width="60">ภาษี</td>
<td align="center" width="60">ตรวจสภาพ</td>
<td align="center" width="60">บริการ</td>
<td align="center" width="60">พรบ.</td>
<td align="center" width="60">ประกันภัย</td>
<td align="center" width="60">รวม</td>
<td align="center" width="60">จักรยานยนต์<br>(รย.12)</td>
<td align="center" width="60">รถเก๋ง<br>(รย.1)</td>
<td align="center" width="60">รถกระบะ<br>(รย.3)</td>
<td align="center" width="60">รถกระบะ<br>4 ประตู<br>(รย.1)</td>
<td align="center" width="60">รถตู้<br>(รย.2)</td>
<td align="center" width="60">อื่นๆ</td>
<td align="center" width="60">รวม</td>
</tr>
</tr>
<?php
$sql ="SELECT date,
SUM(car_p) as sp,
SUM(car_ch) as sch,
SUM(car_se) as sse,
SUM(prb_p) as sprb,
SUM(ins_p) as sins,
SUM(total) as sto,
count(car_type) as ct
FROM money_all WHERE member_id = '$_SESSION[login_true]' AND MONTH(date) ='$m1'
group by date";
$query = $conn->query($sql) or die($conn->error."<br>$sql");
while($ro=$query->fetch_assoc())
{
?>
<tr>
<td align="center" width="60"><?php echo DateThai($ro["date"]);?></td>
<td align="center" width="60"><?php echo ($ro["sp"]);?></td>
<td align="center" width="60"><?php echo ($ro["sch"]);?></td>
<td align="center" width="60"><?php echo ($ro["sse"]);?></td>
<td align="center" width="60"><?php echo ($ro["sprb"]);?></td>
<td align="center" width="60"><?php echo ($ro["sins"]);?></td>
<td align="center" width="60"><?php echo ($ro["sto"]);?></td>
<td align="center" width="60"><?php
echo ($ro["ct"]);?>
</td>
<td align="center" width="60"></td>
<td align="center" width="60"></td>
<td align="center" width="60"></td>
<td align="center" width="60"></td>
<td align="center" width="60"></td>
<td align="center" width="60"></td>
</tr>
<?php } ;?>
มันรวมออกมาหมดเลยแบบนี้
มันไม่ได้แยกประเภทของ name ครับ
ผม sum ข้อมูลชุดอื่นร่วมด้วยและ group by date เพื่อเลือกข้อมูลครับ
|
ประวัติการแก้ไข 2018-10-02 18:19:42 2018-10-02 18:19:50 2018-10-02 18:55:29 2018-10-02 18:57:11 2018-10-02 23:06:10
 |
 |
 |
 |
Date :
2018-10-02 16:56:01 |
By :
lhumdin |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เอาโครงสร้าง database มาดูสิครับ ผมจะรู้ไหมอ่า จะหวงทำม๊ายแค่โครงสร้าง table เอามาแปะ แล้วอธิบายให้ครบเลย
|
 |
 |
 |
 |
Date :
2018-10-02 17:11:50 |
By :
DK |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
group by cartype, date
|
 |
 |
 |
 |
Date :
2018-10-02 22:54:11 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอนนี้ทำได้แล้วครับ ใช้คำสั่ง if เข้ามาช่วยในการดึงข้อมูลครับ
ขอบคุณทุกท่านครับ
|
 |
 |
 |
 |
Date :
2018-10-02 23:20:45 |
By :
lhumdin |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|