我正试图从同一天收集一堆价值。那很好,但是我的问题是我想找到我在SUM中收集的值的ID。
我需要ID,因为我要提取一些数据到具有相同日期的ID。
这是我的桌子的一个例子:
╔════╦══════════╦═════════╦═════════╦═════════════╗
║ id ║ q_tap_1 ║ q_tap_2 ║ q_tap_3 ║ datex ║
╠════╬══════════╬═════════╬═════════╬═════════════╣
║ 1 ║ -1.02 ║ 0.00 ║ 0.00 ║ 24.02.2019 ║
║ 2 ║ -23 ║ -1.23 ║ -354 ║ 24.02.2019 ║
║ 8 ║ -354 ║ -10.23 ║ -29 ║ 28.02.2019 ║
║ 4 ║ 0.00 ║ -4.23 ║ -1.53 ║ 23.02.2019 ║
║ 7 ║ -34 ║ 0.00 ║ 0.00 ║ 23.02.2019 ║
║ 6 ║ -100 ║ -13.63 ║ -54.23 ║ 28.02.2019 ║
║ 9 ║ -1.32 ║ 0.00 ║ 0.00 ║ 28.02.2019 ║
║ 10 ║ -23 ║ 0.00 ║ 0.00 ║ 21.02.2019 ║
║ 11 ║ -5.23 ║ -40.53 ║ -8.32 ║ 21.02.2019 ║
║ 12 ║ -23 ║ -1.23 ║ -23.75 ║ 28.02.2019 ║
╚════╩══════════╩═════════╩═════════╩═════════════╝
这就是现在正在做的事情:
-349 (SUM of all the rows with the same date)
28.02.2019 (Date)
8 (Trying to get all the ids from the same day, but now its only showing the first)
-123
24.02.2019
1
-121
23.02.2019
4
-123
21.02.2019
10
这就是我要尝试的
-349
28.02.2019
8 6 9 12
-123
24.02.2019
1 2
-121
23.02.2019
4 7
-123
21.02.2019
10 11
$sql7 = 'SELECT DATE(datex) as datex, (SUM(q_tap_1) + SUM(q_tap_2) + SUM(q_tap_3) + SUM(q_tap_4) + SUM(q_tap_5) + SUM(q_tap_6)) AS tap, SUM(bonus_gevinst_1) AS gevinst, id FROM `test3` WHERE aktiv LIKE "Nei" GROUP BY DATE(datex) DESC';
$test7 = mysqli_query($conn,$sql7);
<?php
while ($test8 = mysqli_fetch_assoc($test7)) {
$test32 = $test8['gevinst'] + $test8['tap'];
echo '<form method="post">
<input type="hidden" name="id" value="'.$test8['datex'].'">
<li class="list-group-item text-secondary" style="border-color:#17a2b8;margin-bottom:5px;"><div style="display:-webkit-inline-box;"><p class="text-success" style="display: -webkit-inline-box;">'.$test32.'kr</p><br>
<p class="text-info" style="display: -webkit-inline-box;">'.$test8['datex'].'</p>
<p class="text-info" style="display: -webkit-inline-box;">'.$test8['id'].'</p>
</li>
</form>';
};
?>
答案 0 :(得分:1)
您可以group_concat
相关ID:
SELECT DATE(datex) AS datex,
SUM(q_tap_1) +
SUM(q_tap_2) +
SUM(q_tap_3) +
SUM(q_tap_4) +
SUM(q_tap_5) +
SUM(q_tap_6) AS tap,
SUM(bonus_gevinst_1) AS gevinst,
GROUP_CONCAT(id) AS ids -- Here
FROM `test3` WHERE aktiv LIKE "Nei"
GROUP BY DATE(datex)
ORDER BY DATE(datex) DESC