Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT
- -- prod.*,
- prod.id,
- prod.brand_name,
- prod.cat_no,
- pkg.packages
- FROM t_product prod
- -- where magic happens
- LEFT JOIN LATERAL (
- SELECT
- json_agg(k) packages
- FROM t_product_package k
- WHERE k.brand_name = prod.brand_name
- AND k.cat_no = prod.cat_no
- ) pkg
- ON True
- WHERE
- 1 = 1
- AND prod.ID IN (
- SELECT ID
- FROM
- t_product tp
- WHERE
- (
- cn_name ILIKE'%' || '阿莫西林' || '%'
- OR en_name ILIKE'%' || '阿莫西林' || '%'
- OR brand_name = '阿莫西林'
- OR cn_synonym ILIKE'%' || '阿莫西林' || '%'
- OR en_synonym ILIKE'%' || '阿莫西林' || '%'
- OR cat_no = '阿莫西林'
- OR cas ='阿莫西林'
- OR mw = '阿莫西林'
- OR mf ='阿莫西林'
- )
- AND is_delete = 1
- )
- AND ( "brand_name" ='cato' )
- ORDER BY
- similarity ( cat_no,'阿莫西林' ) DESC NULLS LAST,
- similarity ( cas,'阿莫西林' ) DESC NULLS LAST,
- similarity ( cn_name,'阿莫西林' ) DESC NULLS LAST,
- similarity ( en_name,'阿莫西林' ) DESC NULLS LAST,
- similarity ( cn_synonym,'阿莫西林' ) DESC NULLS LAST,
- similarity ( en_synonym,'阿莫西林' ) DESC NULLS LAST,
- similarity ( mf,'阿莫西林' ) DESC NULLS LAST,
- similarity ( mw,'阿莫西林' ) DESC NULLS LAST
- LIMIT 50 OFFSET 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement