1

我尝试使用此选择计算另一个表中的所有项目:

SELECT id, name,  (SELECT count(*) 
                   FROM prekes_main 
                   WHERE prekes_main.pristKaina = 1 
                   and   prekes_main.pg_kodas LIKE 'grupes_main.pg_kodas%') as pristKaina
FROM grupes_main 
WHERE grupes_main.level = 1 
and grupes_main.name <> ''

在 LIKE 子句中我想自动获取选定的 grupes_main 列 pg_kodas,但在这个查询中它总是返回 0,LIKE 函数的错误在哪里?谢谢

4

1 回答 1

4
SELECT  id, name,
        (
        SELECT  COUNT(*)
        FROM    prekes_main
        WHERE   prekes_main.pristKaina = 1
                AND prekes_main.pg_kodas LIKE CONCAT(grupes_main.pg_kodas, '%')
        ) pristKaina
FROM    grupes_main
WHERE   grupes_main.level = 1
        AND grupes_main.name <> ''
于 2012-05-30T13:39:55.447 回答