2017-03-27 10 views
1

PHPMyAdminの「SQL-question section」のコード(コード1、Laravel固有のコードなし)は、LaravelインストールでRAWとして実行すると以下のようになりますエラー:PHPMyAdminではなくLaravelでHAVINGエラーが発生する

SQLSTATE[42000]: Syntax error or access violation: 1463 Non-grouping field 'ip' is used in HAVING clause (SQL: SELECT 
d.id, 
d.domain, 
d.date_expiration, 
d.date_added, 
MAX(CASE WHEN (dm.meta_key = 'domain') THEN dm.meta_value ELSE NULL END) AS domain, 
MAX(CASE WHEN (dm.meta_key = 'ip') THEN dm.meta_value ELSE NULL END) AS ip, 
MAX(CASE WHEN (dm.meta_key = 'link') THEN dm.meta_value ELSE NULL END) AS link, 
MAX(CASE WHEN (dm.meta_key = 'net') THEN dm.meta_value ELSE NULL END) AS net 
FROM 
domain d 
INNER JOIN domain_meta dm 
ON d.id = dm.domain_id 
WHERE 
d.date_expiration >= '2017-03-21' 
GROUP BY d.id, d.domain, d.date_expiration, d.date_added 
HAVING ip > 4 
ORDER BY d.date_expiration ASC 
LIMIT 1000) 

コード1

$domains = DB::select("SELECT 
    d.id, 
    d.domain, 
    d.date_expiration, 
    d.date_added, 
    MAX(CASE WHEN (dm.meta_key = 'domain') THEN dm.meta_value ELSE NULL END) AS domain, 
    MAX(CASE WHEN (dm.meta_key = 'ip') THEN dm.meta_value ELSE NULL END) AS ip, 
    MAX(CASE WHEN (dm.meta_key = 'link') THEN dm.meta_value ELSE NULL END) AS link, 
    MAX(CASE WHEN (dm.meta_key = 'net') THEN dm.meta_value ELSE NULL END) AS net 
FROM 
    domain d 
INNER JOIN domain_meta dm 
ON d.id = dm.domain_id 
WHERE 
    d.date_expiration >= '2017-03-21' 
GROUP BY d.id, d.domain, d.date_expiration, d.date_added 
HAVING ip > 4 
ORDER BY d.date_expiration ASC 
LIMIT 1000"); 

私は行×BY GROUP下IPを追加しようとしましたが、エラーUnknown column 'ip' in 'group statementを得るよりもしています。どのようにしてLaravelの構文でエラーが発生するのですか?

答えて

0

$domains = DB::select("SELECT 
     d.id, 
     d.domain, 
     d.date_expiration, 
     d.date_added, 
     MAX(CASE WHEN (dm.meta_key = 'domain') THEN dm.meta_value ELSE NULL END) AS domain, 
     MAX(CASE WHEN (dm.meta_key = 'ip') THEN dm.meta_value ELSE NULL END) AS ip, 
     MAX(CASE WHEN (dm.meta_key = 'link') THEN dm.meta_value ELSE NULL END) AS link, 
     MAX(CASE WHEN (dm.meta_key = 'net') THEN dm.meta_value ELSE NULL END) AS net 
    FROM 
     domain d 
    INNER JOIN domain_meta dm 
    ON d.id = dm.domain_id 
    WHERE 
     d.date_expiration >= '2017-03-21' 
    GROUP BY d.id, d.domain, d.date_expiration, d.date_added 
    HAVING MAX(CASE WHEN (dm.meta_key = 'ip') THEN dm.meta_value ELSE NULL END) > 4 
    ORDER BY d.date_expiration ASC 
    LIMIT 1000"); 
+0

を持つでエイリアスを使用していない試みるが、それは完璧な仕事をありがとう! –

関連する問題