如何为场景编写查询?

时间:2016-08-20 12:08:14

标签: mysql

如何为我的场景编写单个查询? 我有三个条件?

select * (select * ,'sony' as searchItem from dg_deal_product where name like '%sony%' or
select * , 'samsung' as searchItem from where dg_deal_product where name like '%samsung%' or
select * , 'wip' as searchItem from where dg_deal_product where name like '%wip%') order by column desc,column2 desc,column3;

1 个答案:

答案 0 :(得分:0)

在这里猜测,但也许你正在寻找这样的东西:

SELECT p.*
      ,CASE WHEN p.name LIKE '%sony%' THEN 'sony'
            WHEN p.name LIKE '%samsung%' THEN 'samsung'
            WHEN p.name LIKE '%wip%' THEN 'wip'
            ELSE NULL
       END AS searchItem
FROM dg_deal_product p
ORDER BY 1 DESC, 2 DESC, 3