mysql - sql中如何使用between和大于

标签 mysql sql

table name:tax
       slab1    slab2    tax
        0        10000   0
        10001    50000   10
        50001    100000  20
        100001    0      30

这里0代表无穷大。

我的表是这样的。我要找到60000的税。我不知道如何在sql中一起使用Between和大于。

I tried like this:
$query="SELECT * FROM taxsettings 
        where $liable2 between tax.slab1 and tax.slab2 
           or $liable2 > tax.slab1";

$liable2 是金额。 任何人都可以说出如何将无穷大值插入数据库表

最佳答案

尝试这个查询

"SELECT * FROM taxsettings 
        where $liable2 between case when tax.slab1=0 then $liable2 else tax.slab1 end  and case when tax.slab2 =0 then $liable2 else tax.slab2 end;"

关于mysql - sql中如何使用between和大于,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32200812/

相关文章:

python - 如何阻止 Google Cloud SQL 中的 SQL 注入(inject)?

javascript - PHP 执行时 <a> 链接到其他页面

sql - 在 SQLite 中分页结果的最佳方式

SQL 单列拆分为多列

sql - 持久化 H2 数据库内存模式事务的任何想法?

php - 使用 laravel eloquent 搜索多个表

php - 'field list' php mysql 中的未知列

mysql - Visual Studio 2013 连接到本地 MySQL 数据库

mysqldump 恢复问题

sql - 如果索引用于查询,PostgreSQL 将不会使用索引进行投影