Home >Backend Development >PHP Tutorial >mysql 是否可以将多次查询的结果混合输出?

mysql 是否可以将多次查询的结果混合输出?

WBOY
WBOYOriginal
2016-06-06 20:20:031150browse

1比如,我要价格在20-30 50-60 70-80 价格区间的商品,关系为or
2同时标题要包含裙子,上衣,外套关系为or,
3还要排除标题包含童装,书籍,关系为and,

3个结果合并以id排序,然后取出数据.
这样的语句应该怎么写呀?

回复内容:

1比如,我要价格在20-30 50-60 70-80 价格区间的商品,关系为or
2同时标题要包含裙子,上衣,外套关系为or,
3还要排除标题包含童装,书籍,关系为and,

3个结果合并以id排序,然后取出数据.
这样的语句应该怎么写呀?

select * from tb_name where

<code>      (
         (price between 20 and 30) or 
         (price between 50 and 60) or 
         (price between 70 and 80)
      ) and 
      (
         (title='裙子' or title='上衣' or title='外套') and 
         (title'童装' or title'书籍')
      ) </code>

order by id asc;

(价格区间1 or 价格区间2 or 价格区间3) and (标题1 or 标题2 or 标题3) and (标题 not in(....)) order by id

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn