Я пытаюсь объединить эти две таблицы, которые я создал, чтобы в наборе результатов было 3 записи для каждого типа.
Таблица данных
mysql> SELECT * FROM data;
+--------------+-----------+
| Labels | Data |
+--------------+-----------+
| Component | 1325.1988 |
| Component | 554.1652 |
| Component | 105.4002 |
| Development | 203.4163 |
| Development | 59.4500 |
| Development | 20.4498 |
| Flash Assets | 285.5334 |
| Flash Assets | 302.1501 |
| Flash Assets | 61.1836 |
| Release | 0.6000 |
| Release | 2.3666 |
| Repackage | 416.2169 |
| Repackage | 5195.0839 |
| Repackage | 4.5667 |
| Source Diff | 1.9000 |
| Source Diff | 0.4000 |
+--------------+-----------+
Таблица типов
mysql> SELECT * FROM types ORDER BY Labels;
+------------------------+------+
| Labels | Data |
+------------------------+------+
| Component | 0 |
| Component | 0 |
| Component | 0 |
| Development | 0 |
| Development | 0 |
| Development | 0 |
| Flash Assets | 0 |
| Flash Assets | 0 |
| Flash Assets | 0 |
| Release | 0 |
| Release | 0 |
| Release | 0 |
| Repackage | 0 |
| Repackage | 0 |
| Repackage | 0 |
| Source Diff | 0 |
| Source Diff | 0 |
| Source Diff | 0 |
+------------------------+------+
Текущий запрос:
mysql> SELECT * FROM data d LEFT JOIN types t on t.Labels = d.Labels;
+--------------+-----------+--------------+------+
| Labels | Data | Labels | Data |
+--------------+-----------+--------------+------+
| Component | 1325.1988 | Component | 0 |
| Component | 1325.1988 | Component | 0 |
| Component | 1325.1988 | Component | 0 |
| Component | 554.1652 | Component | 0 |
| Component | 554.1652 | Component | 0 |
| Component | 554.1652 | Component | 0 |
| Component | 105.4002 | Component | 0 |
| Component | 105.4002 | Component | 0 |
| Component | 105.4002 | Component | 0 |
| Development | 203.4163 | Development | 0 |
| Development | 203.4163 | Development | 0 |
| Development | 203.4163 | Development | 0 |
| Development | 59.4500 | Development | 0 |
| Development | 59.4500 | Development | 0 |
| Development | 59.4500 | Development | 0 |
| Development | 20.4498 | Development | 0 |
| Development | 20.4498 | Development | 0 |
| Development | 20.4498 | Development | 0 |
| Flash Assets | 285.5334 | Flash Assets | 0 |
| Flash Assets | 285.5334 | Flash Assets | 0 |
| Flash Assets | 285.5334 | Flash Assets | 0 |
| Flash Assets | 302.1501 | Flash Assets | 0 |
| Flash Assets | 302.1501 | Flash Assets | 0 |
| Flash Assets | 302.1501 | Flash Assets | 0 |
| Flash Assets | 61.1836 | Flash Assets | 0 |
| Flash Assets | 61.1836 | Flash Assets | 0 |
| Flash Assets | 61.1836 | Flash Assets | 0 |
| Release | 0.6000 | Release | 0 |
| Release | 0.6000 | Release | 0 |
| Release | 0.6000 | Release | 0 |
| Release | 2.3666 | Release | 0 |
| Release | 2.3666 | Release | 0 |
| Release | 2.3666 | Release | 0 |
| Repackage | 416.2169 | Repackage | 0 |
| Repackage | 416.2169 | Repackage | 0 |
| Repackage | 416.2169 | Repackage | 0 |
| Repackage | 5195.0839 | Repackage | 0 |
| Repackage | 5195.0839 | Repackage | 0 |
| Repackage | 5195.0839 | Repackage | 0 |
| Repackage | 4.5667 | Repackage | 0 |
| Repackage | 4.5667 | Repackage | 0 |
| Repackage | 4.5667 | Repackage | 0 |
| Source Diff | 1.9000 | Source Diff | 0 |
| Source Diff | 1.9000 | Source Diff | 0 |
| Source Diff | 1.9000 | Source Diff | 0 |
| Source Diff | 0.4000 | Source Diff | 0 |
| Source Diff | 0.4000 | Source Diff | 0 |
| Source Diff | 0.4000 | Source Diff | 0 |
+--------------+-----------+--------------+------+
Моя цель с левым объединением состояла в том, чтобы получить все метки из таблицы Types
, чтобы в наборе результатов было три записи для каждой метки.По какой-то причине все получается просто.
Желаемый результат:
+--------------+-----------+
| Labels | Data |
+--------------+-----------+
| Component | 1325.1988 |
| Component | 554.1652 |
| Component | 105.4002 |
| Development | 203.4163 |
| Development | 59.4500 |
| Development | 20.4498 |
| Flash Assets | 285.5334 |
| Flash Assets | 302.1501 |
| Flash Assets | 61.1836 |
| Release | 0.6000 |
| Release | 0 |
| Release | 2.3666 |
| Repackage | 416.2169 |
| Repackage | 5195.0839 |
| Repackage | 4.5667 |
| Source Diff | 1.9000 |
| Source Diff | 1.9000 |
| Source Diff | 0 |
+--------------+-----------+
Здесь есть три записи для каждой метки, и данные заменяются нулями из таблицы типов
Любая помощь будет отличной.