UNION在MYSQL问题中有多个表

时间:2015-10-18 07:59:28

标签: mysql union

我尝试了但没有运气,我有两张桌子“crm_rentals”和“crm_sales”。

两者都有相同的结构。

Id | portals_name
1  | {dubizzle}{JustRentals}{JustProperty}{propertyfinder}{bayut}
2  | {dubizzle}{JustRentals}{JustProperty}{propertyfinder}{bayut}
3  | {JustRentals}{JustProperty}{propertyfinder}
4  | {dubizzle}{JustProperty}{bayut} 

我想在两个表中获得每个门户的NUMBER,这是我尝试的

select sum(dubizzle) dubizzle,sum(JustRentals) JustRentals,
sum(JustProperty) JustProperty,sum(propertyfinder) propertyfinder 
from ( (select count(id) as dubizzle from crm_rentals where 
portals_name like '%dubizzle%'
UNION
select count(id) as dubizzle from crm_sales where portals_name 
like  '%dubizzle%'
) a ,
(select count(id) as JustRentals from crm_rentals where 
 portals_name like '%JustRentals%'
UNION
select count(id) as JustRentals from crm_sales where 
portals_name like  '%JustRentals%') b,
(select count(id)  as JustProperty from crm_rentals where 
portals_name like '%JustProperty%'
UNION
select count(id)  as JustProperty from crm_sales where portals_name 
like '%JustProperty%') c ,
(select count(id) as propertyfinder from crm_rentals where 
portals_name like '%propertyfinder%'
UNION
select count(id) as propertyfinder from crm_rentals where 
portals_name like '%propertyfinder%'
) d )

我希望得到像

这样的结果
Dubizzle    JustRentals  JustProperty Propertyfinder Others
100           100         100          100            100

问题:我无法得到这个结果,我的查询给了我语法错误。

更新我试过这个但语法错误

select * from (select @table1:=(select count(id) as dubizzle 
from  crm_rentals where portals_name like '%dubizzle%') a,
@table2:=(select count(id) as dubizzle from crm_sales 
where portals_name   like '%dubizzle%') b, (@table1 +@table2) 
as dubizzle) f,
((select @table1:=(select count(id) as JustRentals from 
crm_rentals where portals_name like '%JustRentals%') c,
@table2:=(select count(id) as JustRentals from crm_sales 
where portals_name like '%JustRentals%') d, (@table1 +@table2)
 as JustRentals)  ff) AS f

2 个答案:

答案 0 :(得分:1)

你可以通过这种方式尝试

SELECT * FROM ( 
(select count(id) as dubizzle from crm_rentals where portals_name like '%dubizzle%') AS a,
(select count(id) as JustRentals from crm_rentals where portals_name like '%JustRentals%') b,
(select count(id)  as JustProperty from crm_rentals where portals_name like '%JustProperty%') AS c
UNION
(select count(id) as dubizzle from crm_sales where portals_name like '%dubizzle%') AS a,
(select count(id) as JustRentals from crm_sales where portals_name like  '%JustRentals%') AS b,
(select count(id)  as JustProperty from crm_sales where portals_name like '%JustProperty%') AS c
)   

答案 1 :(得分:0)

class MyActor extends Actor
{
    ...

    public boolean amIBeingDragged = false;

    public void act(float delta)
    {
        super.act(delta);

        if( amIBeingDragged )
        {
            Vector2 position = new Vector2(this.getX(), this.getY());

            for(Actor actor : this.getStage().getActors())
            {
                 if(actor == this) continue;

                 if(position.dst( new Vector2( actor.getX(), actor.getY() < thresholdDistance )
                 {
                     this.setPosition( actor.getX(), actor.getY() );
                 }
            }
        }
    }
}

//drag's listener methods
public void dragStart(InputEvent event, float x, float y, int pointer)
{ 
    ( (MyActor) event.getTarget() ).amIBeingDragged = true;
}

public void dragStop(InputEvent event, float x, float y, int pointer)
{ 
    ( (MyActor) event.getTarget() ).amIBeingDragged = false;
}

...

请尝试此操作并返回此处查询结果。

BTW尽量保持代码清晰:)

相关问题