-1

カテゴリ、素材、ブランドの 3 つの列があります。正直に言うと、単一のテーブルの列ではなく、結合を使用した 8 つの別のテーブルからのクエリの結果です ;)

    |   category  |   material   | brand          |
    ----------------------------------------------|
    |  engines    |  product 1   | abb            | -> unique for category "engines"
    |  engines    |  product 2   | wika           | -> unique for category "engines"
    |  engines    |  product 3   | allen-bradley  | -> unique for category "engines"
    |  engines    |  product 5   | wika           |
    |  engines    |  product 6   | e+h            | -> unique for category "engines"
    |  drives     |  product 7   | abb            | -> unique for category "drives"
    |  drives     |  product 8   | wika           | -> unique for category "drives"
    |  drives     |  product 9   | allen-bradley  | -> unique for category "drives"
    |  drives     |  product 10  | e+h            | -> unique for category "drives"
    |  drives     |  product 11  | e+h            | 

結果として、次のようなsmtが必要です:

    |   category  |   material   | brand          | concat(category, brand) |
    ----------------------------------------------|-------------------------|
    |  engines    |  product *   | abb            | engines/abb             |
    |  engines    |  product *   | wika           | engines/wika            |
    |  engines    |  product *   | allen-bradley  | engines/allen-brandley  |
    |  engines    |  product *   | e+h            | engines/e+h             |
    |  drives     |  product *   | abb            | drives/abb              |
    |  drives     |  product *   | wika           | drives/wika             |  
    |  drives     |  product *   | allen-bradley  | drives/allen-bradley    |
    |  drives     |  product *   | e+h            | drives/e+h              |

「グループ化」ステートメント ( GROUP BY CONCAT() ) を使用すると、クエリ時間が 300 件の結果ごとに 10 秒を超え、満足できません。

グループ内で一意の値を取得する方法を知っている人はいますか?

更新:

SELECT *, CONCAT(url_alias.alias, '/', LOWER(brand_alias.field_brand_path_value)) as real_url 
FROM `taxonomy_term_hierarchy` as th0
LEFT JOIN `taxonomy_term_hierarchy` as th1 ON th0.tid = th1.parent
LEFT JOIN `taxonomy_term_hierarchy` as th2 ON th1.tid = th2.parent
LEFT JOIN `taxonomy_term_hierarchy` as th3 ON th2.tid = th3.parent
LEFT JOIN `taxonomy_term_hierarchy` as th4 ON th3.tid = th4.parent

LEFT JOIN field_data_field_cat_reference as cat_reference ON    
cat_reference.field_cat_reference_tid IN (th0.tid, th1.tid, th2.tid, th3.tid, th4.tid)
LEFT JOIN node n ON cat_reference.entity_id = n.nid
LEFT JOIN field_data_field_brand_reference as brand_reference ON n.nid = brand_reference.entity_id
LEFT JOIN taxonomy_term_data as td_brand ON brand_reference.field_brand_reference_tid = td_brand.tid
LEFT JOIN field_data_field_brand_path as brand_alias ON td_brand.tid = brand_alias.entity_id
LEFT JOIN url_alias ON CONCAT('taxonomy/term/', th0.tid) = url_alias.source
WHERE 1
GROUP BY CONCAT(url_alias.alias, '/', LOWER(brand_alias.field_brand_path_value))
4

2 に答える 2

0

あなたはこのように試すことができます

カテゴリとしてsubstring(new1,0、charindex('/'、new1))、マテリアルとして'product *'、ブランドとしてsubstring(new1、charindex('/'、new1)+1、len(new1))を選択します。new1 from(テーブルからnew1として個別のCategory +'/' + brandを選択)temp

于 2012-08-01T10:27:49.863 に答える
0

試す:

SELECT   a.category, 
         CONCAT(SUBSTRING_INDEX(a.material, ' ', 1), ' *') AS material,
         brand,
         CONCAT(a.category, '/', a.brand) AS concattedval
FROM     (
             [Your Sub-Select Query]
         ) a
GROUP BY a.category, 
         material, 
         a.brand
于 2012-07-31T18:47:41.403 に答える