我有以下查询:
SELECT b.id, b.bouquet, JSON_LENGTH(c.sort) - IFNULL(JSON_LENGTH(JSON_EXTRACT(c.sort, REPLACE(JSON_SEARCH(c.sort, 'all', '%m%'), '"', ''))), 0) AS total FROM bouquets b, channels c
LEFT JOIN streams st ON JSON_SEARCH(c.sort, 'one', st.id) IS NOT NULL
LEFT JOIN streams s ON JSON_SEARCH(s.bouquet, 'one', b.id) IS NOT NULL
GROUP BY b.id ASC ORDER BY b.bouquet ASC;
我得到错误:
ERROR 1054 (42S22): Unknown column 'b.id' in 'on clause'
我尝试解决这个问题,但我不明白......导致此错误的原因是什么以及如何解决?
更新问题:使用表格结构,这样可以更容易地跟踪如何修复mysql返回的错误。
mysql> SELECT * FROM bouquets;
+----+-----------+
| id | bouquet |
+----+-----------+
| 1 | Mega |
| 2 | Resellers |
| 33 | Exchange |
| 28 | Ex-Yu |
| 5 | Albanian |
+----+-----------+
5 rows in set (0.00 sec)
mysql> SELECT * FROM channels;
+----+--------------------------+---------+----------+
| id | sort | bouquet | reseller |
+----+--------------------------+---------+----------+
| 1 | ["m1","1","2","11","m2"] | ["1"] | 1 |
| 27 | ["m1","1","2","m2"] | ["28"] | 1 |
| 39 | [] | ["33"] | 1 |
+----+--------------------------+---------+----------+
3 rows in set (0.00 sec)
mysql> SELECT * FROM streams;
+----+-------------------+--------------------------------------------------------------------+------------+------------+-------+-------+------+-----------------------+---------------------------------------------+---------------+---------+--------+
| id | channel | stream | server | bouquet | notes | adult | epg | acodec | vcodec | uptime | bitrate | status |
+----+-------------------+--------------------------------------------------------------------+------------+------------+-------+-------+------+-----------------------+---------------------------------------------+---------------+---------+--------+
| 1 | CH1 1 | ["http://"] | ["1","15"] | ["1","28"] | | 0 | 0 | mp3 ( VBR: 125 kb/s ) | h264 ( FPS: 25.0 , 720 x 576 , DAR: 16:9 ) | 1528448246933 | 1221 | 1 |
| 2 | CH1 2 | ["http://"] | ["1"] | ["1","28"] | | 0 | 0 | mp3 ( VBR: 125 kb/s ) | h264 ( FPS: 25.0 , 720 x 576 , DAR: 16:9 ) | 1528448259003 | 1194 | 1 |
| 11 | CH1 3 | ["http://"] | ["1","15"] | ["1"] | | 0 | 0 | mp3 ( VBR: 125 kb/s ) | h264 ( FPS: 25.0 , 720 x 576 , DAR: 16:9 ) | 1528448252725 | 1288 | 1 |
| 12 | CH1 4 | ["http://"] | ["15"] | ["28"] | | 0 | 0 | mp2 ( VBR: 125 kb/s ) | h264 ( FPS: 50.0 , 720 x 576 , DAR: 20:11 ) | 1528448256089 | 1995 | 1 |
+----+-------------------+--------------------------------------------------------------------+------------+------------+-------+-------+------+-----------------------+---------------------------------------------+---------------+---------+--------+
4 rows in set (0.01 sec)
答案 0 :(得分:1)
尝试完整定义列名称,如bouquets.id
和channels.sort
可能
答案 1 :(得分:1)
确保花束(b)中的列ID可用。试一试:b。id
或花束。id
答案 2 :(得分:0)
我找到了解决方案:
SELECT b.id, b.bouquet, IFNULL(JSON_LENGTH(c.sort) - JSON_LENGTH(JSON_SEARCH(c.sort, 'all', '%m%')), 0) AS total FROM bouquets b
LEFT JOIN channels c ON JSON_SEARCH(c.bouquet, 'one', b.id) IS NOT NULL
GROUP BY b.id, b.bouquet, total ORDER BY b.bouquet ASC;
这让我:
+----+-----------+-------+
| id | bouquet | total |
+----+-----------+-------+
| 5 | Albanian | 0 |
| 28 | Ex-Yu | 2 |
| 33 | Exchange | 0 |
| 1 | Mega | 3 |
| 2 | Resellers | 0 |
+----+-----------+-------+
感谢大家帮助我。