0

I have a problem getting markup_category value.

I have to calculate product retail prices.

retail_price = price + (price / 100 * markup_category)

So when product category has markup_category it is not problem. But sometimes category does not have this value and then parent category markup must be used. I can not take its value in one query.

Table structure:

category_id parent_id markup_category
168 0 50.00
1048 168 0.00
1092 1048 0.00

And when I try to do something like: (took query here: How do I import an SQL file using the command line in MySQL?)

SELECT category_id, @pv:=parent_id AS parent_id, markup_category FROM cscart_categories JOIN (SELECT @pv:=1092) tmp WHERE category_id=@pv

I get only this as result:

category_id parent_id markup_category
1048 168 0.00
1092 1048 0.00

How to get first category with markup_category > 0 ?

8
  • Excuse me, took query here stackoverflow.com/questions/20215744/… Commented Jan 26, 2022 at 19:22
  • you mean that question and its answers answered your question? Commented Jan 26, 2022 at 19:32
  • @ysth No, just firstly added incorrect link to original question. I still have problem to get markup_category Commented Jan 26, 2022 at 19:55
  • what does select version(); show? Commented Jan 26, 2022 at 20:08
  • @ysth 10.3.32-MariaDB Commented Jan 26, 2022 at 20:20

1 Answer 1

1

This helped me in this case

WITH RECURSIVE markup_categories AS (
    SELECT 
        category_id, 
        parent_id, 
        markup_category 
    FROM 
        cscart_categories 
    WHERE 
        category_id = 1092 
    UNION ALL 
    SELECT 
        c2.category_id, 
        c2.parent_id, 
        c2.markup_category 
    FROM 
        cscart_categories AS c2, 
        markup_categories AS mc 
    WHERE 
        c2.category_id = mc.parent_id
) 
SELECT 
    * 
FROM 
    markup_categories
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.