1
我正在使用woocomerce平臺,並且有重複的產品名稱條目。現在,我想查看由用戶組輸入的具有特定類別名稱的重複「product_name」的categories_id,categories_name,products_name。如何在woocomerce中使用sql選擇重複產品
正如我在數據庫表中看到,這裏有需要的表來查看結果:根據下表模式
:
--------------------------
| categories_description |
--------------------------
categories_id(PK)
categories_name
-----------------------
| products_description |
-----------------------
products_id
products_name
----------------------
|products_to_categories |
-----------------------
products_id
categories_id
我的查詢:
SELECT prod.products_id, `products_name`, categories_name,
prodcat.categories_id , count(*) c
FROM
(products_description AS prod INNER JOIN products_to_categories AS
prodcat ON prod.products_id=prodcat.products_id)
INNER JOIN
categories_description AS catdesc ON
catdesc.categories_id=prodcat.categories_id AND categories_name= 'CARD
HOLDERS'
GROUP BY products_name
order by categories_name
我的查詢的問題是,它無法顯示條目列表重複產品名稱。
example Inputs:
products_description
---------------------------
products_id | products_name
1 pens
2 pens
3 cars
4 cars
5 cars
6 burgers
products_to_categories
-------------------------------
products_id | categories_id
1 1
2 1
3 2
4 2
5 2
6 3
categories_description
------------------------------
categories_id | categories_name
1 School Supply
2 Vehicles
3 Foods
=================================
Expected Output
=================================
products_name categories_name categories_id total_count
pens School Supply 1 2
cars Vehicles 2 3
burgers Foods 3 1
看看總數。這取決於products_description表中出現的次數
請幫忙。
我看不到在子查詢了'SELECT'。你的查詢是否運行?向我們展示樣品輸入和所需輸出。 –
請參閱樣本修改後的問題。, – smzapp