如何执行基于类别的选择查询条件

时间:2018-12-28 09:08:05

标签: sql oracle plsql

我有这样的桌子

id  category  minLimit  maxLimit  count  
11  Bannana     100       200      50
12  Bannana     200       300      20  
13  Bannana     300       400      40  
14  Apple       100       200      60  
15  Apple       200       300      70  

现在我将执行查询查询,并按限制250返回Bannana,按限制150返回Apple。 在这种情况下,我可以这样运行q查询:

select  
   * 
from main_table 
where 
   (category = 'Bannana' and minLimit <= 250 and maxLimit > 250) or 
   (category = 'Apple' and minLimit <= 150 and maxLimit > 150)

在另一个解决方案中,我可以创建一个额外的表,插入我的where子句条件(Bannana 250,Apple 150)数据并使用main_table进行联接。我想知道什么是最有效的解决方案?

注意:我的where子句条件(Bannana-250,Apple 150)在实际情况下超过5000条记录

1 个答案:

答案 0 :(得分:1)

不,没有什么比要求数据库执行其构建目的更有效的方法:联接数据。将5000条记录插入另一个表,然后执行以下操作:

typo3_src-9.5.3:

Requested URL: http://demo.domain/ultxswkov.html

typo3_src-9.5.1:

Requested URL: http://demo.domain/hpwymspohv.html   
Requested URL: http://demo.domain/txlkcgnaet.html 
Requested URL: http://demo.domain/contact.php   
Requested URL: http://demo.domain/kontakt.html
Requested URL: http://demo.domain/kontakt.htm
Requested URL: http://demo.domain/kontakt
Requested URL: http://demo.domain/contact-us.html
Requested URL: http://demo.domain/contacts.htm
Requested URL: http://demo.domain/contacts.html
...

然后:

 <div **draggable="true"** class="modal" id="addServiceProduct" role="dialog" [ngStyle]="{'display':addServiceModal}">
<div class="modal-dialog modal-lg" id="draggable">
  <div class="modal-content">
    <div class="modal-header">
      <h5 class="modal-title" id="exampleModalLabel">
        {{this.editIndex>0?(this.viewProduct?'View Product':'Edit Product'):'Add Product'}} <span>-</span> {{serviceModel.Name}}
        <button class="close" type="button" data-dismiss="modal" aria-label="Close" (click)="closeAddProduct()">
          <span aria-hidden="true">×</span>
        </button>
      </h5>
    </div>
    <div class="modal-body">
      This is header