0

以下を使用して、サブクエリによって返される一意の値をカウントしようとしています。

(SELECT COUNT(DISTINCT pm.id) FROM parts_manufacturers AS pm,
 parts_trading AS pt, enquiries 
 WHERE pm.id = pt.manufacturer AND pt.enquiryRef = enquiries.id 
 AND enquiries.entityRef = eo.id) AS manufacturers

しかし、エラーが発生します:

General error: 2014 Cannot execute queries while other unbuffered queries are active

今まで見たことがない。

サブクエリが複数の行を返すため、groupbyを使用して重複を排除することもできません。

どこが間違っているのでしょうか。また、サブクエリで一意の値のみをカウントするにはどうすればよいですか。


phpmyadminで実行しようとすると、メモリ不足エラーが発生します。

#5 - Out of memory (Needed 268435428 bytes)

完全なクエリは次のとおりです。

SELECT SQL_CALC_FOUND_ROWS eo.id, name, eia.county, $valueColumn $averageColumn
                        (SELECT CONCAT_WS(' ', entity_contacts.name, entity_contacts.lastName) FROM entity_contacts WHERE entityRef = eo.id AND isPrimary = 1 LIMIT 1) AS contact,
                        (SELECT ect.tel FROM entity_contacts AS ec, entity_contacts_telephones AS ect WHERE ect.contactRef = ec.id AND entityRef = eo.id AND ec.isPrimary = 1 LIMIT 1) AS tel,
                         countries.country AS countryName, CONCAT('images/flags/',LOWER(countryCode),'.gif') AS country, (SELECT COUNT(*) FROM enquiries WHERE entityRef = eo.id) AS enquired,
                         (SELECT COUNT(*) FROM enquiries, jobs WHERE enquiries.id = jobs.enquiryRef AND entityRef = eo.id AND jobs.stateRef != 5) AS jobCount,
                         ept.term AS paymentTerms, ei.type,
                         (SELECT COUNT(DISTINCT pm.id) as colname
                         FROM parts_manufacturers AS pm 
                        left outer join  parts_trading AS pt on pm.id = pt.manufacturer 
                        left outer join  enquiries on  pt.enquiryRef = enquiries.id
                         WHERE enquiries.entityRef = eo.id) AS manufacturers
                         FROM entity_details AS eo
                         LEFT JOIN entity_invoice_addresses AS eia ON eo.id = eia.entityRef AND eia.isPrimary = 1
                         LEFT JOIN countries ON eia.countryRef = countries.id
                         LEFT JOIN entity_industry_types AS ei ON ei.id = eo.industryTypeRef
                         LEFT JOIN entity_payment_terms AS ept ON eo.paymentTermsRef = ept.id,
                         users
                         WHERE eo.typeRef = 3
                         AND eo.deleted = 0
                         AND eo.ownerRef = users.id
                         LIMIT ?, ?
4

1 に答える 1

0

私はどこから来たのですか eo.id ..

ですから、明確にして返信してください:

    (SELECT COUNT(DISTINCT pm.id) as colname
         FROM parts_manufacturers AS pm 
        left outer join  parts_trading AS pt on pm.id = pt.manufacturer 
        left outer join  enquiries  on  pt.enquiryRef = enquiries.id
         WHERE enquiries.entityRef = eo.id) AS manufacturers

試してみてください:私はユーザーをテーブルに参加するように変更します:--->

SELECT SQL_CALC_FOUND_ROWS eo.id, name, eia.county, $valueColumn $averageColumn
                        (SELECT CONCAT_WS(' ', entity_contacts.name, entity_contacts.lastName) FROM entity_contacts WHERE entityRef = eo.id AND isPrimary = 1 LIMIT 1) AS contact,
                        (SELECT ect.tel FROM entity_contacts AS ec, entity_contacts_telephones AS ect WHERE ect.contactRef = ec.id AND entityRef = eo.id AND ec.isPrimary = 1 LIMIT 1) AS tel,
                         countries.country AS countryName, CONCAT('images/flags/',LOWER(countryCode),'.gif') AS country, (SELECT COUNT(*) FROM enquiries WHERE entityRef = eo.id) AS enquired,
                         (SELECT COUNT(*) FROM enquiries, jobs WHERE enquiries.id = jobs.enquiryRef AND entityRef = eo.id AND jobs.stateRef != 5) AS jobCount,
                         ept.term AS paymentTerms, ei.type,
                         (SELECT COUNT(DISTINCT pm.id) as colname
                         FROM parts_manufacturers AS pm 
                        left outer join  parts_trading AS pt on pm.id = pt.manufacturer 
                        left outer join  enquiries on  pt.enquiryRef = enquiries.id
                         WHERE enquiries.entityRef = eo.id) AS manufacturers
                         FROM entity_details AS eo
                         LEFT outer JOIN entity_invoice_addresses AS eia ON eo.id = eia.entityRef AND eia.isPrimary = 1
                         LEFT outer JOIN countries ON eia.countryRef = countries.id
                         LEFT outer JOIN entity_industry_types AS ei ON ei.id = eo.industryTypeRef
                         LEFT outer JOIN entity_payment_terms AS ept ON eo.paymentTermsRef = ept.id,
                         LEFT outer JOIN users ON eo.ownerRef = users.id                          
                         WHERE eo.typeRef = 3
                         AND eo.deleted = 0                       
                         LIMIT ?, ?
于 2012-10-10T11:20:02.493 に答える