如何为狮身人面像创建正确的索引
How create the correct index for the sphinx
我有桌子:
product
| id | shop_id | name |
| 1 | 1 | p1 |
| 2 | 1 | p2 |
| 3 | 2 | p3 |
etc
shop
| id | name |
| 1 | s1 |
| 2 | s2 |
| 3 | s3 |
| 4 | s4 |
etc
country
| id | name |
| 1 | russia |
| 2 | usa |
etc
shop_country
|id | shop_id | country_id |
| 1 | 1 | 1 |
| 2 | 1 | 2 |
| 3 | 2 | 1 |
我需要获取在指定国家/地区可用的商品。
这是 mysql 的工作要求:
SELECT *
FROM product AS p
LEFT JOIN shop_country sc ON (p.shop_id = sc.shop_id)
WHERE product.status = 1 mc.country_id = 3
我创建了一个索引:
SELECT product.id as id, product.shop_id \
FROM product \
LEFT JOIN shop_country sc ON (product.shop_id = sc.shop_id) \
GROUP BY product.id
但它产生了错误的结果
我需要什么才能在狮身人面像中得到这个?
GROUP BY product.id
表示您有多个国家/地区销售同一产品
SELECT product.id as id, product.shop_id \
无群组功能
所以替换为
SELECT product.id as id, group_concat(product.shop_id) \
并尝试设置
shop_id 作为 sql_attr_multi
我有桌子:
product
| id | shop_id | name |
| 1 | 1 | p1 |
| 2 | 1 | p2 |
| 3 | 2 | p3 |
etc
shop
| id | name |
| 1 | s1 |
| 2 | s2 |
| 3 | s3 |
| 4 | s4 |
etc
country
| id | name |
| 1 | russia |
| 2 | usa |
etc
shop_country
|id | shop_id | country_id |
| 1 | 1 | 1 |
| 2 | 1 | 2 |
| 3 | 2 | 1 |
我需要获取在指定国家/地区可用的商品。
这是 mysql 的工作要求:
SELECT *
FROM product AS p
LEFT JOIN shop_country sc ON (p.shop_id = sc.shop_id)
WHERE product.status = 1 mc.country_id = 3
我创建了一个索引:
SELECT product.id as id, product.shop_id \
FROM product \
LEFT JOIN shop_country sc ON (product.shop_id = sc.shop_id) \
GROUP BY product.id
但它产生了错误的结果
我需要什么才能在狮身人面像中得到这个?
GROUP BY product.id
表示您有多个国家/地区销售同一产品
SELECT product.id as id, product.shop_id \
无群组功能
所以替换为
SELECT product.id as id, group_concat(product.shop_id) \
并尝试设置 shop_id 作为 sql_attr_multi