我有这张RAW表:
==================================================== | id | name | fieldid | info1 | info2 | ==================================================== | 1 | testname1 | 1 | testing 1 | testing 2 | |----|-----------|---------|-----------|-----------| | 2 | testname2 | 2 | testing 3 | testing 4 | |----|-----------|---------|-----------|-----------| | 3 | testname2 | 2 | testing 5 | testing 6 | ====================================================
我希望使用'名称'和' fieldid'作为表格的参考,看起来像这样:
======================================= | id | name | fieldid | info | ======================================= | 1 | testname1 | 1 | testing1 | | | | | testing2 | |----|-----------|---------|----------| | 2 | testname2 | 2 | testing3 | | | | | testing4 | | | | | testing5 | | | | | testing6 | =======================================
我的代码目前生成了这个:
========================================= | id | name | fieldid | info | ========================================= | 1 | testname1 | 1 | testing1 | | | | | testing2 | |----|-----------|-----------|----------| | 2 | testname2 | 2 | testing3 | | | | | testing4 | | | | | testing6 | |----| |-----------|----------|------------ | 3 | | testname2 | 2 | testing 5 | | | | | | testing 4 | | | | | | testing 6 | =====================================================
以下是代码:
select
sum(if( r.type = 'a', r.amount, 0)) as sum_a,
sum(if( r.type = 'b', r.amount, 0)) as sum_b
from records r;
我已经阅读了相关的问题,但没有一个与我的相关。
答案 0 :(得分:0)
我建议以不同的方式解决它。
你要做的第一件事就是建立一个像
这样的多维数组$entries[1][testName1][fieldId] = [entry1, entry2, entry3];
$entries[2][testName2][fieldId] = [entry1, entry2, entry3];
$entries[3][testName2][fieldId] = []; // "Not found"
一旦建立了阵列,就可以更容易地在HTML表格中输出。调试起来要容易得多。