'Stuff' And 'FOR XML PATH' alternative in Mysql for the following stored prodedure of Ms-sql

StackOverflow https://stackoverflow.com/questions/20738142

  •  20-09-2022
  •  | 
  •  

문제

I have the following query in Ms-Sql

  INSERT INTO tbl_web_price_update 

    Select bd_book_code,

    Case 
        When pd.bpd_price is null then  
            cast((a.bd_price*c.ptm_price) as numeric(10))   
        else
            cast((pd.bpd_price*c.ptm_price) as numeric(10))             
        end
    As Price

    from tbl_books_details a 
        inner join tbl_price_type_master c on a.bd_price_type = c.ptm_price_type_id 
        left join tbl_books_price_details pd on pd.bpd_book_code = a.bd_book_code 
    Where c.ptm_price_type_id = @price_type     

    SELECT distinct r.price, STUFF((SELECT distinct ','+ Cast(a.bd_book_code as varchar) FROM tbl_web_price_update a WHERE r.price = a.price FOR XML PATH(''), TYPE).value('.','VARCHAR(max)'), 1, 1, '') FROM tbl_web_price_update r

I have migrated from ms-sql to my-sql and i am unable to write an alternative query in Mysql. Please Help.

도움이 되었습니까?

해결책

It looks like you're looking for something like this

SELECT price, GROUP_CONCAT(DISTINCT bd_book_code) bd_book_code
  FROM tbl_web_price_update
 GROUP BY price

Here is SQLFiddle demo

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top