使用x-'WHERE'语句计算记录并将其分配给x个变量

时间:2012-02-06 03:34:59

标签: mysql

表格realestate中的

我希望得到 字段address <&lt; = 5且&gt; = 0的记录数,并将其分配给counta
字段address为&lt; = 12且&gt; = 6并将其分配给countb

的记录数

依旧......

2 个答案:

答案 0 :(得分:1)

select (select count(address) 
        from realestate 
        where address <= 5 and address >= 0) as counta,
       (select count(address) 
        from realestate 
        where address <= 12 and adress >= 6) as countb

答案 1 :(得分:1)

可能更容易阅读between

select
    (select count(address) from realestate 
    where address between 0 and 5) as counta,
    (select count(address) from realestate 
    where address between 6 and 12) as countb
相关问题