问:
How to use crosstab or pivote in mysql query to get month names dynamicaly?
I have table named user_plan_dtl with the columns userid, plan description and contact date. I want count of users in each month according to plan description. And month should get selected only within a given date range.
I have database in mysql.

Below is the table user_plan_dtl

```<code>userid        contactdate  plandesc
USR001           March       ICMA
USR003           March       ICMA
USR004           April       FTDA
USR005           April       FTDA
USR006           April       FTDA
USR007           April       ICMA
USR008           April       ICMA
USR009           May         FTDA
USR002           May         FTDA
USR001           May         ICMA
</code>```

I want output like :

```<code> Count    March  April  May
 Total     2      5      3
 FTDA      0      3      2
 ICMA      2      2      1
</code>```

I have tried with below query but I am getting output for all the months.

```<code>select  d.Plandesc as AssignedUsers, max(d.January) as January,max(d.February) as February,max(d.March) as March,
max(d.April) as April ,max(d.May)as May,max(d.June)as June,
max(d.July) as July,max(d.August)as August,max(d.September) as September,
max(d.October)as October,max(d.November) as November ,max(d.December)as December from
(Select Plandesc,
COUNT(DISTINCT(CASE WHEN MONTHNAME(contactdate)='January' THEN userid END )) AS January,
COUNT(DISTINCT(CASE WHEN MONTHNAME(contactdate)='February' THEN userid END )) AS February,
COUNT(DISTINCT(CASE WHEN MONTHNAME(contactdate)='March' THEN userid END )) AS March,
COUNT(DISTINCT(CASE WHEN MONTHNAME(contactdate)='April' THEN userid END )) AS April,
COUNT(DISTINCT(CASE WHEN MONTHNAME(contactdate)='May' THEN userid END )) AS May,
COUNT(DISTINCT(CASE WHEN MONTHNAME(contactdate)='June' THEN userid END )) AS June,
COUNT(DISTINCT(CASE WHEN MONTHNAME(contactdate)='July' THEN userid END )) AS July,
COUNT(DISTINCT(CASE WHEN MONTHNAME(contactdate)='August' THEN userid END )) AS August,
COUNT(DISTINCT(CASE WHEN MONTHNAME(contactdate)='September' THEN userid END )) AS September,
COUNT(DISTINCT(CASE WHEN MONTHNAME(contactdate)='October' THEN userid END )) AS October,
COUNT(DISTINCT(CASE WHEN MONTHNAME(contactdate)='November' THEN userid END )) AS November,
COUNT(DISTINCT(CASE WHEN MONTHNAME(contactdate)='December' THEN userid END )) AS December
from user_plan_dtl
where Plandesc in ('FTDA','ICMA')
and DATE_FORMAT(contactdate, '%Y-%m-%d') >= '2017-01-01' and DATE_FORMAT(contactdate, '%Y-%m-%d') <= '2017-07-05'
group by  MONTHNAME(contactdate),Plandesc
union all
Select 'Total' as Plandesc,
COUNT(DISTINCT(CASE WHEN MONTHNAME(contactdate)='January' THEN userid END )) AS January,
COUNT(DISTINCT(CASE WHEN MONTHNAME(contactdate)='February' THEN userid END )) AS February,
COUNT(DISTINCT(CASE WHEN MONTHNAME(contactdate)='March' THEN userid END )) AS March,
COUNT(DISTINCT(CASE WHEN MONTHNAME(contactdate)='April' THEN userid END )) AS April,
COUNT(DISTINCT(CASE WHEN MONTHNAME(contactdate)='May' THEN userid END )) AS May,
COUNT(DISTINCT(CASE WHEN MONTHNAME(contactdate)='June' THEN userid END )) AS June,
COUNT(DISTINCT(CASE WHEN MONTHNAME(contactdate)='July' THEN userid END )) AS July,
COUNT(DISTINCT(CASE WHEN MONTHNAME(contactdate)='August' THEN userid END )) AS August,
COUNT(DISTINCT(CASE WHEN MONTHNAME(contactdate)='September' THEN userid END )) AS September,
COUNT(DISTINCT(CASE WHEN MONTHNAME(contactdate)='October' THEN userid END )) AS October,
COUNT(DISTINCT(CASE WHEN MONTHNAME(contactdate)='November' THEN userid END )) AS November,
COUNT(DISTINCT(CASE WHEN MONTHNAME(contactdate)='December' THEN userid END )) AS December
from user_plan_dtl
where Plandesc in ('FTDA','ICMA')
and DATE_FORMAT(contactdate, '%Y-%m-%d') >= '2017-01-01' and DATE_FORMAT(contactdate, '%Y-%m-%d') <= '2017-07-05'
group by  MONTHNAME(contactdate)
) as d group by d.Plandesc order by case when d.Plandesc = 'Total' then 0 else 1 end,d.Plandesc
</code>```

Can anyone plaese provide me the solution for this? Thanks in advance.

答:
I came up with this solution, setting variables and using prepared statements:</p>

```<code>DROP TABLE IF EXISTS user_plan_temp;

SET @JanTotal = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc IN ('FTDA','ICMA') AND MONTHNAME(contactdate)='January' );
SET @FebTotal = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc IN ('FTDA','ICMA') AND MONTHNAME(contactdate)='February');
SET @MarTotal = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc IN ('FTDA','ICMA') AND MONTHNAME(contactdate)='March');
SET @AprTotal = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc IN ('FTDA','ICMA') AND MONTHNAME(contactdate)='April');
SET @MayTotal = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc IN ('FTDA','ICMA') AND MONTHNAME(contactdate)='May');
SET @JunTotal = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc IN ('FTDA','ICMA') AND MONTHNAME(contactdate)='June');
SET @JulTotal = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc IN ('FTDA','ICMA') AND MONTHNAME(contactdate)='July');
SET @AugTotal = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc IN ('FTDA','ICMA') AND MONTHNAME(contactdate)='August');
SET @SepTotal = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc IN ('FTDA','ICMA') AND MONTHNAME(contactdate)='September');
SET @OctTotal = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc IN ('FTDA','ICMA') AND MONTHNAME(contactdate)='October');
SET @NovTotal = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc IN ('FTDA','ICMA') AND MONTHNAME(contactdate)='November');
SET @DecTotal = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc IN ('FTDA','ICMA') AND MONTHNAME(contactdate)='December');

SET @SQLq = 'CREATE TEMPORARY TABLE user_plan_temp AS (SELECT "Total" AS Count ';
SET @SQLq = CONCAT(@SQLq, IF(@JanTotal > 0, ', @JanTotal AS January',''));
SET @SQLq = CONCAT(@SQLq, IF(@FebTotal > 0, ', @FebTotal AS February',''));
SET @SQLq = CONCAT(@SQLq, IF(@MarTotal > 0, ', @MarTotal AS March',''));
SET @SQLq = CONCAT(@SQLq, IF(@AprTotal > 0, ', @AprTotal AS April',''));
SET @SQLq = CONCAT(@SQLq, IF(@MayTotal > 0, ', @MayTotal AS May',''));
SET @SQLq = CONCAT(@SQLq, IF(@JunTotal > 0, ', @JunTotal AS June',''));
SET @SQLq = CONCAT(@SQLq, IF(@JulTotal > 0, ', @JulTotal AS July',''));
SET @SQLq = CONCAT(@SQLq, IF(@AugTotal > 0, ', @AugTotal AS August',''));
SET @SQLq = CONCAT(@SQLq, IF(@SepTotal > 0, ', @SepTotal AS September',''));
SET @SQLq = CONCAT(@SQLq, IF(@OctTotal > 0, ', @OctTotal AS October',''));
SET @SQLq = CONCAT(@SQLq, IF(@NovTotal > 0, ', @NovTotal AS November',''));
SET @SQLq = CONCAT(@SQLq, IF(@DecTotal > 0, ', @DecTotal AS December',''));
SET @SQLq = CONCAT(@SQLq, ')');
PREPARE stmt1 FROM @SQLq;
EXECUTE stmt1;
DEALLOCATE PREPARE stmt1;
-- SELECT * FROM user_plan_temp;

SET @SQLq2 = 'INSERT INTO user_plan_temp VALUES("FTDA" ';
SET @JanFTDA = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc = 'FTDA' AND MONTHNAME(contactdate)='January' );
SET @SQLq2 = CONCAT(@SQLq2, IF(@JanTotal > 0, ', @JanFTDA',''));
SET @FebFTDA = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc = 'FTDA' AND MONTHNAME(contactdate)='February');
SET @SQLq2 = CONCAT(@SQLq2, IF(@FebTotal > 0, ', @FebFTDA',''));
SET @MarFTDA = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc = 'FTDA' AND MONTHNAME(contactdate)='March');
SET @SQLq2 = CONCAT(@SQLq2, IF(@MarTotal > 0, ', @MarFTDA',''));
SET @AprFTDA = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc = 'FTDA' AND MONTHNAME(contactdate)='April');
SET @SQLq2 = CONCAT(@SQLq2, IF(@AprTotal > 0, ', @AprFTDA',''));
SET @MayFTDA = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc = 'FTDA' AND MONTHNAME(contactdate)='May');
SET @SQLq2 = CONCAT(@SQLq2, IF(@MayTotal > 0, ', @MayFTDA',''));
SET @JunFTDA = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc = 'FTDA' AND MONTHNAME(contactdate)='June');
SET @SQLq2 = CONCAT(@SQLq2, IF(@JunTotal > 0, ', @JunFTDA',''));
SET @JulFTDA = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc = 'FTDA' AND MONTHNAME(contactdate)='July');
SET @SQLq2 = CONCAT(@SQLq2, IF(@JulTotal > 0, ', @JulFTDA',''));
SET @AugFTDA = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc = 'FTDA' AND MONTHNAME(contactdate)='August');
SET @SQLq2 = CONCAT(@SQLq2, IF(@AugTotal > 0, ', @AugFTDA',''));
SET @SepFTDA = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc = 'FTDA' AND MONTHNAME(contactdate)='September');
SET @SQLq2 = CONCAT(@SQLq2, IF(@SepTotal > 0, ', @SepFTDA',''));
SET @OctFTDA = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc = 'FTDA' AND MONTHNAME(contactdate)='October');
SET @SQLq2 = CONCAT(@SQLq2, IF(@OctTotal > 0, ', @OctFTDA',''));
SET @NovFTDA = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc = 'FTDA' AND MONTHNAME(contactdate)='November');
SET @SQLq2 = CONCAT(@SQLq2, IF(@NovTotal > 0, ', @NovFTDA',''));
SET @DecFTDA = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc = 'FTDA' AND MONTHNAME(contactdate)='December');
SET @SQLq2 = CONCAT(@SQLq2, IF(@DecTotal > 0, ', @DecFTDA',''));
SET @SQLq2 = CONCAT(@SQLq2, ')');
-- SELECT @SQLq2;
PREPARE stmt2 FROM @SQLq2;
EXECUTE stmt2;
DEALLOCATE PREPARE stmt2;

SET @SQLq3 = 'INSERT INTO user_plan_temp VALUES("FTDA" ';
SET @JanICMA = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc = 'ICMA' AND MONTHNAME(contactdate)='January' );
SET @SQLq3 = CONCAT(@SQLq3, IF(@JanTotal > 0, ', @JanICMA',''));
SET @FebICMA = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc = 'ICMA' AND MONTHNAME(contactdate)='February');
SET @SQLq3 = CONCAT(@SQLq3, IF(@FebTotal > 0, ', @FebICMA',''));
SET @MarICMA = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc = 'ICMA' AND MONTHNAME(contactdate)='March');
SET @SQLq3 = CONCAT(@SQLq3, IF(@MarTotal > 0, ', @MarICMA',''));
SET @AprICMA = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc = 'ICMA' AND MONTHNAME(contactdate)='April');
SET @SQLq3 = CONCAT(@SQLq3, IF(@AprTotal > 0, ', @AprICMA',''));
SET @MayICMA = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc = 'ICMA' AND MONTHNAME(contactdate)='May');
SET @SQLq3 = CONCAT(@SQLq3, IF(@MayTotal > 0, ', @MayICMA',''));
SET @JunICMA = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc = 'ICMA' AND MONTHNAME(contactdate)='June');
SET @SQLq3 = CONCAT(@SQLq3, IF(@JunTotal > 0, ', @JunICMA',''));
SET @JulICMA = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc = 'ICMA' AND MONTHNAME(contactdate)='July');
SET @SQLq3 = CONCAT(@SQLq3, IF(@JulTotal > 0, ', @JulICMA',''));
SET @AugICMA = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc = 'ICMA' AND MONTHNAME(contactdate)='August');
SET @SQLq3 = CONCAT(@SQLq3, IF(@AugTotal > 0, ', @AugICMA',''));
SET @SepICMA = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc = 'ICMA' AND MONTHNAME(contactdate)='September');
SET @SQLq3 = CONCAT(@SQLq3, IF(@SepTotal > 0, ', @SepICMA',''));
SET @OctICMA = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc = 'ICMA' AND MONTHNAME(contactdate)='October');
SET @SQLq3 = CONCAT(@SQLq3, IF(@OctTotal > 0, ', @OctICMA',''));
SET @NovICMA = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc = 'ICMA' AND MONTHNAME(contactdate)='November');
SET @SQLq3 = CONCAT(@SQLq3, IF(@NovTotal > 0, ', @NovICMA',''));
SET @DecICMA = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc = 'ICMA' AND MONTHNAME(contactdate)='December');
SET @SQLq3 = CONCAT(@SQLq3, IF(@DecTotal > 0, ', @DecICMA',''));
SET @SQLq3 = CONCAT(@SQLq3, ')');
PREPARE stmt3 FROM @SQLq3;
EXECUTE stmt3;
DEALLOCATE PREPARE stmt3;

SELECT * FROM user_plan_temp;
</code>```

Body:
I have table named user_plan_dtl with the columns userid, plan description and contact date. I want count of users in each month according to plan description. And month should get selected only within a given date range.
I have database in mysql.

Below is the table user_plan_dtl

userid        contactdate  plandesc
USR001           March       ICMA
USR003           March       ICMA
USR004           April       FTDA
USR005           April       FTDA
USR006           April       FTDA
USR007           April       ICMA
USR008           April       ICMA
USR009           May         FTDA
USR002           May         FTDA
USR001           May         ICMA

I want output like :

 Count    March  April  May
 Total     2      5      3
 FTDA      0      3      2
 ICMA      2      2      1

I have tried with below query but I am getting output for all the months.

select  d.Plandesc as AssignedUsers, max(d.January) as January,max(d.February) as February,max(d.March) as March,
max(d.April) as April ,max(d.May)as May,max(d.June)as June,
max(d.July) as July,max(d.August)as August,max(d.September) as September,
max(d.October)as October,max(d.November) as November ,max(d.December)as December from
(Select Plandesc,
COUNT(DISTINCT(CASE WHEN MONTHNAME(contactdate)='January' THEN userid END )) AS January,
COUNT(DISTINCT(CASE WHEN MONTHNAME(contactdate)='February' THEN userid END )) AS February,
COUNT(DISTINCT(CASE WHEN MONTHNAME(contactdate)='March' THEN userid END )) AS March,
COUNT(DISTINCT(CASE WHEN MONTHNAME(contactdate)='April' THEN userid END )) AS April,
COUNT(DISTINCT(CASE WHEN MONTHNAME(contactdate)='May' THEN userid END )) AS May,
COUNT(DISTINCT(CASE WHEN MONTHNAME(contactdate)='June' THEN userid END )) AS June,
COUNT(DISTINCT(CASE WHEN MONTHNAME(contactdate)='July' THEN userid END )) AS July,
COUNT(DISTINCT(CASE WHEN MONTHNAME(contactdate)='August' THEN userid END )) AS August,
COUNT(DISTINCT(CASE WHEN MONTHNAME(contactdate)='September' THEN userid END )) AS September,
COUNT(DISTINCT(CASE WHEN MONTHNAME(contactdate)='October' THEN userid END )) AS October,
COUNT(DISTINCT(CASE WHEN MONTHNAME(contactdate)='November' THEN userid END )) AS November,
COUNT(DISTINCT(CASE WHEN MONTHNAME(contactdate)='December' THEN userid END )) AS December
from user_plan_dtl
where Plandesc in ('FTDA','ICMA')
and DATE_FORMAT(contactdate, '%Y-%m-%d') >= '2017-01-01' and DATE_FORMAT(contactdate, '%Y-%m-%d') <= '2017-07-05'
group by  MONTHNAME(contactdate),Plandesc
union all
Select 'Total' as Plandesc,
COUNT(DISTINCT(CASE WHEN MONTHNAME(contactdate)='January' THEN userid END )) AS January,
COUNT(DISTINCT(CASE WHEN MONTHNAME(contactdate)='February' THEN userid END )) AS February,
COUNT(DISTINCT(CASE WHEN MONTHNAME(contactdate)='March' THEN userid END )) AS March,
COUNT(DISTINCT(CASE WHEN MONTHNAME(contactdate)='April' THEN userid END )) AS April,
COUNT(DISTINCT(CASE WHEN MONTHNAME(contactdate)='May' THEN userid END )) AS May,
COUNT(DISTINCT(CASE WHEN MONTHNAME(contactdate)='June' THEN userid END )) AS June,
COUNT(DISTINCT(CASE WHEN MONTHNAME(contactdate)='July' THEN userid END )) AS July,
COUNT(DISTINCT(CASE WHEN MONTHNAME(contactdate)='August' THEN userid END )) AS August,
COUNT(DISTINCT(CASE WHEN MONTHNAME(contactdate)='September' THEN userid END )) AS September,
COUNT(DISTINCT(CASE WHEN MONTHNAME(contactdate)='October' THEN userid END )) AS October,
COUNT(DISTINCT(CASE WHEN MONTHNAME(contactdate)='November' THEN userid END )) AS November,
COUNT(DISTINCT(CASE WHEN MONTHNAME(contactdate)='December' THEN userid END )) AS December
from user_plan_dtl
where Plandesc in ('FTDA','ICMA')
and DATE_FORMAT(contactdate, '%Y-%m-%d') >= '2017-01-01' and DATE_FORMAT(contactdate, '%Y-%m-%d') <= '2017-07-05'
group by  MONTHNAME(contactdate)
) as d group by d.Plandesc order by case when d.Plandesc = 'Total' then 0 else 1 end,d.Plandesc

Can anyone plaese provide me the solution for this? Thanks in advance.

Body:
I came up with this solution, setting variables and using prepared statements:

DROP TABLE IF EXISTS user_plan_temp;

SET @JanTotal = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc IN ('FTDA','ICMA') AND MONTHNAME(contactdate)='January' );
SET @FebTotal = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc IN ('FTDA','ICMA') AND MONTHNAME(contactdate)='February');
SET @MarTotal = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc IN ('FTDA','ICMA') AND MONTHNAME(contactdate)='March');
SET @AprTotal = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc IN ('FTDA','ICMA') AND MONTHNAME(contactdate)='April');
SET @MayTotal = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc IN ('FTDA','ICMA') AND MONTHNAME(contactdate)='May');
SET @JunTotal = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc IN ('FTDA','ICMA') AND MONTHNAME(contactdate)='June');
SET @JulTotal = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc IN ('FTDA','ICMA') AND MONTHNAME(contactdate)='July');
SET @AugTotal = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc IN ('FTDA','ICMA') AND MONTHNAME(contactdate)='August');
SET @SepTotal = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc IN ('FTDA','ICMA') AND MONTHNAME(contactdate)='September');
SET @OctTotal = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc IN ('FTDA','ICMA') AND MONTHNAME(contactdate)='October');
SET @NovTotal = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc IN ('FTDA','ICMA') AND MONTHNAME(contactdate)='November');
SET @DecTotal = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc IN ('FTDA','ICMA') AND MONTHNAME(contactdate)='December');

SET @SQLq = 'CREATE TEMPORARY TABLE user_plan_temp AS (SELECT "Total" AS Count ';
SET @SQLq = CONCAT(@SQLq, IF(@JanTotal > 0, ', @JanTotal AS January',''));
SET @SQLq = CONCAT(@SQLq, IF(@FebTotal > 0, ', @FebTotal AS February',''));
SET @SQLq = CONCAT(@SQLq, IF(@MarTotal > 0, ', @MarTotal AS March',''));
SET @SQLq = CONCAT(@SQLq, IF(@AprTotal > 0, ', @AprTotal AS April',''));
SET @SQLq = CONCAT(@SQLq, IF(@MayTotal > 0, ', @MayTotal AS May',''));
SET @SQLq = CONCAT(@SQLq, IF(@JunTotal > 0, ', @JunTotal AS June',''));
SET @SQLq = CONCAT(@SQLq, IF(@JulTotal > 0, ', @JulTotal AS July',''));
SET @SQLq = CONCAT(@SQLq, IF(@AugTotal > 0, ', @AugTotal AS August',''));
SET @SQLq = CONCAT(@SQLq, IF(@SepTotal > 0, ', @SepTotal AS September',''));
SET @SQLq = CONCAT(@SQLq, IF(@OctTotal > 0, ', @OctTotal AS October',''));
SET @SQLq = CONCAT(@SQLq, IF(@NovTotal > 0, ', @NovTotal AS November',''));
SET @SQLq = CONCAT(@SQLq, IF(@DecTotal > 0, ', @DecTotal AS December',''));
SET @SQLq = CONCAT(@SQLq, ')');
PREPARE stmt1 FROM @SQLq;
EXECUTE stmt1;
DEALLOCATE PREPARE stmt1;
-- SELECT * FROM user_plan_temp;

SET @SQLq2 = 'INSERT INTO user_plan_temp VALUES("FTDA" ';
SET @JanFTDA = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc = 'FTDA' AND MONTHNAME(contactdate)='January' );
SET @SQLq2 = CONCAT(@SQLq2, IF(@JanTotal > 0, ', @JanFTDA',''));
SET @FebFTDA = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc = 'FTDA' AND MONTHNAME(contactdate)='February');
SET @SQLq2 = CONCAT(@SQLq2, IF(@FebTotal > 0, ', @FebFTDA',''));
SET @MarFTDA = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc = 'FTDA' AND MONTHNAME(contactdate)='March');
SET @SQLq2 = CONCAT(@SQLq2, IF(@MarTotal > 0, ', @MarFTDA',''));
SET @AprFTDA = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc = 'FTDA' AND MONTHNAME(contactdate)='April');
SET @SQLq2 = CONCAT(@SQLq2, IF(@AprTotal > 0, ', @AprFTDA',''));
SET @MayFTDA = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc = 'FTDA' AND MONTHNAME(contactdate)='May');
SET @SQLq2 = CONCAT(@SQLq2, IF(@MayTotal > 0, ', @MayFTDA',''));
SET @JunFTDA = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc = 'FTDA' AND MONTHNAME(contactdate)='June');
SET @SQLq2 = CONCAT(@SQLq2, IF(@JunTotal > 0, ', @JunFTDA',''));
SET @JulFTDA = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc = 'FTDA' AND MONTHNAME(contactdate)='July');
SET @SQLq2 = CONCAT(@SQLq2, IF(@JulTotal > 0, ', @JulFTDA',''));
SET @AugFTDA = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc = 'FTDA' AND MONTHNAME(contactdate)='August');
SET @SQLq2 = CONCAT(@SQLq2, IF(@AugTotal > 0, ', @AugFTDA',''));
SET @SepFTDA = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc = 'FTDA' AND MONTHNAME(contactdate)='September');
SET @SQLq2 = CONCAT(@SQLq2, IF(@SepTotal > 0, ', @SepFTDA',''));
SET @OctFTDA = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc = 'FTDA' AND MONTHNAME(contactdate)='October');
SET @SQLq2 = CONCAT(@SQLq2, IF(@OctTotal > 0, ', @OctFTDA',''));
SET @NovFTDA = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc = 'FTDA' AND MONTHNAME(contactdate)='November');
SET @SQLq2 = CONCAT(@SQLq2, IF(@NovTotal > 0, ', @NovFTDA',''));
SET @DecFTDA = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc = 'FTDA' AND MONTHNAME(contactdate)='December');
SET @SQLq2 = CONCAT(@SQLq2, IF(@DecTotal > 0, ', @DecFTDA',''));
SET @SQLq2 = CONCAT(@SQLq2, ')');
-- SELECT @SQLq2;
PREPARE stmt2 FROM @SQLq2;
EXECUTE stmt2;
DEALLOCATE PREPARE stmt2;

SET @SQLq3 = 'INSERT INTO user_plan_temp VALUES("FTDA" ';
SET @JanICMA = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc = 'ICMA' AND MONTHNAME(contactdate)='January' );
SET @SQLq3 = CONCAT(@SQLq3, IF(@JanTotal > 0, ', @JanICMA',''));
SET @FebICMA = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc = 'ICMA' AND MONTHNAME(contactdate)='February');
SET @SQLq3 = CONCAT(@SQLq3, IF(@FebTotal > 0, ', @FebICMA',''));
SET @MarICMA = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc = 'ICMA' AND MONTHNAME(contactdate)='March');
SET @SQLq3 = CONCAT(@SQLq3, IF(@MarTotal > 0, ', @MarICMA',''));
SET @AprICMA = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc = 'ICMA' AND MONTHNAME(contactdate)='April');
SET @SQLq3 = CONCAT(@SQLq3, IF(@AprTotal > 0, ', @AprICMA',''));
SET @MayICMA = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc = 'ICMA' AND MONTHNAME(contactdate)='May');
SET @SQLq3 = CONCAT(@SQLq3, IF(@MayTotal > 0, ', @MayICMA',''));
SET @JunICMA = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc = 'ICMA' AND MONTHNAME(contactdate)='June');
SET @SQLq3 = CONCAT(@SQLq3, IF(@JunTotal > 0, ', @JunICMA',''));
SET @JulICMA = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc = 'ICMA' AND MONTHNAME(contactdate)='July');
SET @SQLq3 = CONCAT(@SQLq3, IF(@JulTotal > 0, ', @JulICMA',''));
SET @AugICMA = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc = 'ICMA' AND MONTHNAME(contactdate)='August');
SET @SQLq3 = CONCAT(@SQLq3, IF(@AugTotal > 0, ', @AugICMA',''));
SET @SepICMA = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc = 'ICMA' AND MONTHNAME(contactdate)='September');
SET @SQLq3 = CONCAT(@SQLq3, IF(@SepTotal > 0, ', @SepICMA',''));
SET @OctICMA = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc = 'ICMA' AND MONTHNAME(contactdate)='October');
SET @SQLq3 = CONCAT(@SQLq3, IF(@OctTotal > 0, ', @OctICMA',''));
SET @NovICMA = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc = 'ICMA' AND MONTHNAME(contactdate)='November');
SET @SQLq3 = CONCAT(@SQLq3, IF(@NovTotal > 0, ', @NovICMA',''));
SET @DecICMA = (Select COUNT(DISTINCT(userid)) from user_plan_dtl WHERE plandesc = 'ICMA' AND MONTHNAME(contactdate)='December');
SET @SQLq3 = CONCAT(@SQLq3, IF(@DecTotal > 0, ', @DecICMA',''));
SET @SQLq3 = CONCAT(@SQLq3, ')');
PREPARE stmt3 FROM @SQLq3;
EXECUTE stmt3;
DEALLOCATE PREPARE stmt3;

SELECT * FROM user_plan_temp;


来源: stackexchange

问:
window.opener is undefined in Microsoft Edge
I have many popup window.open, used to search for an item, that call back a javascript function from the window.opener to select that item (when the user click on it).

That worked forever in all browsers, but it is not into Edge. I found out that window.opener is "undefined" in Edge only.
It doesn't matter if I try it locally or on my web server, I got the same problem.
And it can't be a security cross-domain thing, my popup are pages from the same web site.

Is there something I missed about Edge? A new requirement the way we use window.open?

For example, if I have an input button that does:

```<code>window.open('search.aspx','searching');
</code>```

and a javascript function into head part like:

```<code>function SelectItem(ID)
{
    // insert magic here
    alert('test');
}
</code>```

The following javascript code from search.aspx doesn't work in Edge:

```<code>window.opener.SelectItem(123);
</code>```

And if I changed it to

```<code>alert(window.opener);
</code>```

I will see it is undefined.

Edit 1:
No, it is not a duplicate of Window.opener in Microsoft Edge undefined when running at localhost. I already read this question before asking mine. My problem is happening not only from localhost, but from web server also. It is not a hostname problem.

Edit 2:
Easy way to test it, I get the same problem from the w3schools "Try it yourself" example: https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_win_open3

Update (solution): I had this problem with Edge 38.14393 (Windows 10 version 1607). I just upgrade to Win10 version 1803 (Edge 42.17134) and now it's working fine as expected. Might been a bug in previous Edge version!

答:
Instead of using window.opener to get a reference to the parent window function. You can assign a function to the newly opened widow like so:

```<code>function SelectItem(ID)
{
    // insert magic here
    alert('test');
}

var popup = window.open('search.aspx','searching');

if(popup) {
    popup.SelectItem = SelectItem;
}
</code>```

In your popup you can now call SelectItem.

ContentLicense: CC BY-SA 4.0

Body:
I have many popup window.open, used to search for an item, that call back a javascript function from the window.opener to select that item (when the user click on it).

That worked forever in all browsers, but it is not into Edge. I found out that window.opener is "undefined" in Edge only.
It doesn't matter if I try it locally or on my web server, I got the same problem.
And it can't be a security cross-domain thing, my popup are pages from the same web site.

Is there something I missed about Edge? A new requirement the way we use window.open?

For example, if I have an input button that does:

window.open('search.aspx','searching');

and a javascript function into head part like:

function SelectItem(ID)
{
    // insert magic here
    alert('test');
}

The following javascript code from search.aspx doesn't work in Edge:

window.opener.SelectItem(123);

And if I changed it to

alert(window.opener);

I will see it is undefined.

Edit 1:
No, it is not a duplicate of Window.opener in Microsoft Edge undefined when running at localhost. I already read this question before asking mine. My problem is happening not only from localhost, but from web server also. It is not a hostname problem.

Edit 2:
Easy way to test it, I get the same problem from the w3schools "Try it yourself" example: https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_win_open3

Update (solution): I had this problem with Edge 38.14393 (Windows 10 version 1607). I just upgrade to Win10 version 1803 (Edge 42.17134) and now it's working fine as expected. Might been a bug in previous Edge version!

Body:
Instead of using window.opener to get a reference to the parent window function. You can assign a function to the newly opened widow like so:

function SelectItem(ID)
{
    // insert magic here
    alert('test');
}

var popup = window.open('search.aspx','searching');

if(popup) {
    popup.SelectItem = SelectItem;
}

In your popup you can now call SelectItem.

ContentLicense: CC BY-SA 3.0


问:
How do i search through directories and return a file to a JTextArea
I want to be able to go through a folder containing files and display the files that have been specified. I currently have it hard coded... Cc

```<code>public void searchResult(String a) throws IOException {

    FileReader inputFile;
    a = "C:\\IO\\Project.txt";
    try {
        inputFile = new FileReader(a);
        BufferedReader br = new BufferedReader(inputFile);

        while ((str = br.readLine()) != null) {
            searchResult.setText(str);
        }

    } catch (FileNotFoundException ex) {
        Logger.getLogger(SearchResults.class.getName()).log(Level.SEVERE, null, ex);
    }

}
</code>```

Please, I need something more dynamic.

答:
i currently have it hard coded

Do you understand how passing parameters work?

```<code>public void searchResult(String a) throws IOException
{
    a = "C:\\IO\\Project.txt";

    try {
        inputFile = new FileReader(a);
</code>```

What is the point of hardcoding the value of "a". The point of using parameters is to pass the file name as a parameter to you method.

So the code should simply be:

```<code>public void searchResult(String a) throws IOException
{
    try {
        inputFile = new FileReader(a);
</code>```

Also the following makes no sense:

```<code>while ((str = br.readLine()) != null) {
    searchResult.setText(str);
</code>```

Every time you read a new line of text you replace the previous line of text. You need to append(...) the text.

Or, the better solution is to just use the read(...) method of the JTextArea to load data from the file.

Body:
I want to be able to go through a folder containing files and display the files that have been specified. I currently have it hard coded... Cc

public void searchResult(String a) throws IOException {

    FileReader inputFile;
    a = "C:\\IO\\Project.txt";
    try {
        inputFile = new FileReader(a);
        BufferedReader br = new BufferedReader(inputFile);

        while ((str = br.readLine()) != null) {
            searchResult.setText(str);
        }

    } catch (FileNotFoundException ex) {
        Logger.getLogger(SearchResults.class.getName()).log(Level.SEVERE, null, ex);
    }

}

Please, I need something more dynamic.

Body:
i currently have it hard coded

Do you understand how passing parameters work?

public void searchResult(String a) throws IOException
{
    a = "C:\\IO\\Project.txt";

    try {
        inputFile = new FileReader(a);

What is the point of hardcoding the value of "a". The point of using parameters is to pass the file name as a parameter to you method.

So the code should simply be:

public void searchResult(String a) throws IOException
{
    try {
        inputFile = new FileReader(a);

Also the following makes no sense:

while ((str = br.readLine()) != null) {
    searchResult.setText(str);

Every time you read a new line of text you replace the previous line of text. You need to append(...) the text.

Or, the better solution is to just use the read(...) method of the JTextArea to load data from the file.


问:
3 Android GPS Questions
1) For some reason, the longitude and latitude are slightly different after storing  them. For example, when i first find them, they are:
25.171057657111998 and 35.013447496224636 but after I store them , they are
25.1710586547852 and 35.0134468078613. Why is this happening? I store them as floats in an sqlite database, retrieve them with Cursor.getFloat, and print them with String.format of 13 digit accuracy.Can this difference affect the end results in a significant way? I am working with distances <100m (328 feet)

2)I am trying to find the center of a location cluster. Here
http://www.geomidpoint.com/calculation.html
method C says I can just take a simple average if I work with <400km. Has anyone tried it? Is it working? Or should I go for the first, more accurate method?

3) After finding the center, do I need anything else to create a new location object for distance purposes?

答:
To solve this problem you may store longitude and latitude in your sqlite database by this way:

longitude*10^10 , latitude*10^10

when you get them you will divide them by 10^10.

because with 5 decimal is accurate

Title: 3 Android GPS Questions


问:
Triggering Two Instances of the Same Class - Javascript
I have a menu system where there are two hamburger menus.  I'm trying to work out how to have JS trigger both instances of these menu icons. They both have all have the same classes.

I've tried adding a for loop, to loop through anything with the instance of the classes, but this didn't seem to work, and I'm going around in endless circles now.

With the code below I've kept the index number of the three menu bars in the first hamburger men at zero[0] so that you can see the desired effect of what happens when you click on the top hamburger menu.

I'd like it so that when I click on either hamburger menu the animation of the bars happens on both icons and the state of the blue box changes.

Any help would be amazing.

Codepen link is here: https://codepen.io/emilychews/pen/jwwVam

Code is below.

JAVASCRIPT

```<code>var container = document.getElementsByClassName('container')[0],
    bar1 = document.getElementsByClassName('bar1')[0],
    bar2 = document.getElementsByClassName('bar2')[0],
    bar3 = document.getElementsByClassName('bar3')[0],
    box = document.getElementsByClassName('box')[0],
    openMenu = false; // used for toggle

container.onclick = function(){

  if(openMenu === false) {

    bar1.classList.add("bar1_open");
    bar2.classList.add("bar2_open");
    bar3.classList.add("bar3_open");

    box.classList.add("changeBackground");

    openMenu = true;

  } else {

    bar1.classList.remove("bar1_open");
    bar2.classList.remove("bar2_open");
    bar3.classList.remove("bar3_open");

    box.classList.remove("changeBackground");

    openMenu = false;
  }

};
</code>```

CSS

```<code>* {padding: 0; margin: 0;}
body {height: 200vh; font-family: arial;}
/* red square */
.container {
  margin: 10px;
  width: 100px;
  height: 100px;
  background: red;
  padding: 0px;
  position: relative;
}

/* properties for all menu bar lines */
.bar {
  position: absolute;
  height: 4px;
  width: 60px;
  background: blue;
  left: 20px;
}

/* 1st menu line */
.bar1 {
  position: absolute;
  top: 28px;
  margin: 0 auto;
  transform-origin: top right;
  transition: transform .5s;
}

/* 2nd menu line */
.bar2 {
  position: absolute;
  top: 48px;
  margin: 0 auto;
  transition: opacity 1s;
}

/* 3rd menu line */
.bar3 {
  position: absolute;
  top: 68px;
  margin: 0 auto;
  transform-origin: right bottom;
  transition: transform .5s;
}

.bar1_open{
  transform-origin: top right;
  transform: rotate(-45deg) translate(-7px, -7px);
  transition: transform .5s .1s ease-out ;
}

.bar2_open {
  opacity: 0;
  transition: opacity .2s ease-in;
}

.bar3_open {
  top: 69px;
  transform-origin: right bottom;
  transform: rotate(45deg)  translate(-7px, 7px);
  transition: transform .5s .1s ease-out;
}

.box {
  padding: 10px;
  width: 200px;
  height: 100px;
  background: blue;
  position: absolute;
  left: 300px;
  top: 30px;
  z-index: 99;
  color: white;
  display: flex;
  justify-content: center;
  align-items: center

}

.changeBackground {
  background: red;
}
</code>```

HTML

```<code><div class="container">
  <div class="bar bar1"></div>
  <div class="bar bar2"></div>
  <div class="bar bar3"></div>
</div>

<!-- second hamburger menu button that currently has no JS  -->
<div class="container">
  <div class="bar bar1"></div>
  <div class="bar bar2"></div>
  <div class="bar bar3"></div>
</div>

<div class="box"> This toggles after 1st hamburger menu is clicked</div>
</code>```

答:
If you are ok with using JQuery this works perfect:

HTML(link to jquery):

```<code><script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
</code>```

Javascript:

```<code>var container = document.getElementsByClassName('container')[0];

console.log(container);
var bar1 = document.getElementsByClassName('bar1')[0],
    bar2 = document.getElementsByClassName('bar2')[0],
    bar3 = document.getElementsByClassName('bar3')[0],
    box = document.getElementsByClassName('box')[0],
    openMenu = false; // used for toggle

    $(".container").click(function(){

     if(openMenu === false) {

     $(".bar1").addClass("bar1_open");
     $(".bar2").addClass("bar2_open");
     $(".bar3").addClass("bar3_open");

     box.classList.add("changeBackground");

     openMenu = true;

   } else {

     $(".bar1").removeClass("bar1_open");
     $(".bar2").removeClass("bar2_open");
     $(".bar3").removeClass("bar3_open");

     box.classList.remove("changeBackground");

     openMenu = false;
  }

});
</code>```

Body:
I have a menu system where there are two hamburger menus.  I'm trying to work out how to have JS trigger both instances of these menu icons. They both have all have the same classes.

I've tried adding a for loop, to loop through anything with the instance of the classes, but this didn't seem to work, and I'm going around in endless circles now.

With the code below I've kept the index number of the three menu bars in the first hamburger men at zero[0] so that you can see the desired effect of what happens when you click on the top hamburger menu.

I'd like it so that when I click on either hamburger menu the animation of the bars happens on both icons and the state of the blue box changes.

Any help would be amazing.

Codepen link is here: https://codepen.io/emilychews/pen/jwwVam

Code is below.

JAVASCRIPT

var container = document.getElementsByClassName('container')[0],
    bar1 = document.getElementsByClassName('bar1')[0],
    bar2 = document.getElementsByClassName('bar2')[0],
    bar3 = document.getElementsByClassName('bar3')[0],
    box = document.getElementsByClassName('box')[0],
    openMenu = false; // used for toggle

container.onclick = function(){

  if(openMenu === false) {

    bar1.classList.add("bar1_open");
    bar2.classList.add("bar2_open");
    bar3.classList.add("bar3_open");

    box.classList.add("changeBackground");

    openMenu = true;

  } else {

    bar1.classList.remove("bar1_open");
    bar2.classList.remove("bar2_open");
    bar3.classList.remove("bar3_open");

    box.classList.remove("changeBackground");

    openMenu = false;
  }

};

CSS

* {padding: 0; margin: 0;}
body {height: 200vh; font-family: arial;}
/* red square */
.container {
  margin: 10px;
  width: 100px;
  height: 100px;
  background: red;
  padding: 0px;
  position: relative;
}

/* properties for all menu bar lines */
.bar {
  position: absolute;
  height: 4px;
  width: 60px;
  background: blue;
  left: 20px;
}

/* 1st menu line */
.bar1 {
  position: absolute;
  top: 28px;
  margin: 0 auto;
  transform-origin: top right;
  transition: transform .5s;
}

/* 2nd menu line */
.bar2 {
  position: absolute;
  top: 48px;
  margin: 0 auto;
  transition: opacity 1s;
}

/* 3rd menu line */
.bar3 {
  position: absolute;
  top: 68px;
  margin: 0 auto;
  transform-origin: right bottom;
  transition: transform .5s;
}

.bar1_open{
  transform-origin: top right;
  transform: rotate(-45deg) translate(-7px, -7px);
  transition: transform .5s .1s ease-out ;
}

.bar2_open {
  opacity: 0;
  transition: opacity .2s ease-in;
}

.bar3_open {
  top: 69px;
  transform-origin: right bottom;
  transform: rotate(45deg)  translate(-7px, 7px);
  transition: transform .5s .1s ease-out;
}

.box {
  padding: 10px;
  width: 200px;
  height: 100px;
  background: blue;
  position: absolute;
  left: 300px;
  top: 30px;
  z-index: 99;
  color: white;
  display: flex;
  justify-content: center;
  align-items: center

}

.changeBackground {
  background: red;
}

HTML

 This toggles after 1st hamburger menu is clicked

Body:
If you are ok with using JQuery this works perfect:

HTML(link to jquery):

<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>

Javascript:

var container = document.getElementsByClassName('container')[0];

console.log(container);
var bar1 = document.getElementsByClassName('bar1')[0],
    bar2 = document.getElementsByClassName('bar2')[0],
    bar3 = document.getElementsByClassName('bar3')[0],
    box = document.getElementsByClassName('box')[0],
    openMenu = false; // used for toggle

    $(".container").click(function(){

     if(openMenu === false) {

     $(".bar1").addClass("bar1_open");
     $(".bar2").addClass("bar2_open");
     $(".bar3").addClass("bar3_open");

     box.classList.add("changeBackground");

     openMenu = true;

   } else {

     $(".bar1").removeClass("bar1_open");
     $(".bar2").removeClass("bar2_open");
     $(".bar3").removeClass("bar3_open");

     box.classList.remove("changeBackground");

     openMenu = false;
  }

});


问:
Emulator in Android Studio doesn't start
I think it's a problem with the SDK reference in Project Structure, but when I click run and I choose Launch Emulator nothing appears.</p>

答:
It seems that "Waiting for target device to come online ..." is a generic message that appears, always, when the emulator can not start properly. And what's the cause of that? As you can see, there could be many causes.

I think the best way to find the concrete error with the emulator is to start it within a terminal. So:

1 - Open a terminal and go to this folder:~/Android/Sdk/tools

2 - Start the emulator with this command:

```<code>./emulator -avd EMULATOR_NAME -netspeed full -netdelay none
</code>```

You can see the name of your (previously created with AVD Manager) emulators with this command:

```<code>./emulator -list-avds
</code>```

If everything is ok, the program doesn't start, and it writes in the terminal the concrete error.

In my case, the application says that there is a problem loading the graphic driver ("libGL error: unable to load driver: r600_dri.so"). As it is explained here, it seems that Google packaged with Android Studio an old version of one library, and the emulator fails when it tries to use my graphic card.

The solution? Very easy: to use the system libraries instead of the packaged in Android Studio. How? Adding "-use-system-libs" at the end of the command. So:

```<code>./emulator -avd EMULATOR_NAME -netspeed full -netdelay none -use-system-libs
</code>```

The definitive solution is to set the ANDROID_EMULATOR_USE_SYSTEM_LIBS environment variable to 1 for your user/system. With this change, when I run the emulator within Android Studio, it will also load the system libraries.

PS 1 - The easiest way I found to set the environment variable, it's to modify the script that launches the Android Studio (studio.sh, in my case it is inside /opt/android-stuido/bin), and add at the beginning this:

```<code>export ANDROID_EMULATOR_USE_SYSTEM_LIBS=1
</code>```

PS 2 - I work with Debian Jessie and Android Studio 2.2.3. My graphic card is an ATI Radeon HD 6850 by Sapphire.

UPDATE December 2017: I had the same problem with Debian Stretch and Android Studio 3.0.1 (same graphic card). The same solution works for me.

Body:
It seems that "Waiting for target device to come online ..." is a generic message that appears, always, when the emulator can not start properly. And what's the cause of that? As you can see, there could be many causes.

I think the best way to find the concrete error with the emulator is to start it within a terminal. So:

1 - Open a terminal and go to this folder:~/Android/Sdk/tools

2 - Start the emulator with this command:

./emulator -avd EMULATOR_NAME -netspeed full -netdelay none

You can see the name of your (previously created with AVD Manager) emulators with this command:

./emulator -list-avds

If everything is ok, the program doesn't start, and it writes in the terminal the concrete error.

In my case, the application says that there is a problem loading the graphic driver ("libGL error: unable to load driver: r600_dri.so"). As it is explained here, it seems that Google packaged with Android Studio an old version of one library, and the emulator fails when it tries to use my graphic card.

The solution? Very easy: to use the system libraries instead of the packaged in Android Studio. How? Adding "-use-system-libs" at the end of the command. So:

./emulator -avd EMULATOR_NAME -netspeed full -netdelay none -use-system-libs

The definitive solution is to set the ANDROID_EMULATOR_USE_SYSTEM_LIBS environment variable to 1 for your user/system. With this change, when I run the emulator within Android Studio, it will also load the system libraries.

PS 1 - The easiest way I found to set the environment variable, it's to modify the script that launches the Android Studio (studio.sh, in my case it is inside /opt/android-stuido/bin), and add at the beginning this:

export ANDROID_EMULATOR_USE_SYSTEM_LIBS=1

PS 2 - I work with Debian Jessie and Android Studio 2.2.3. My graphic card is an ATI Radeon HD 6850 by Sapphire.

UPDATE December 2017: I had the same problem with Debian Stretch and Android Studio 3.0.1 (same graphic card). The same solution works for me.


问:
Arguments to function not getting passed in correctly MASM
I'm learning MASM and I can't get this simple code to work. I'm not getting the values I pass into invoke, I don't know what's happening. I've tried push 2, push 2, call pow. Same results. EAX and EDX look like garbage or maybe memory addresses.

The thread 0x1544 has exited with code -1073741510 (0xc000013a).
The thread 0xd8 has exited with code -1073741510 (0xc000013a).
The thread 0x898 has exited with code -1073741510 (0xc000013a).
The thread 0x21c4 has exited with code -1073741510 (0xc000013a).
The program '[2296] AssemblyTutorial.exe' has exited with code -1073741510 (0xc000013a).

This just means I closed the console window, but why are there 4 threads?

```<code>.386
.model flat,stdcall
option casemap:none

include windows.inc

include masm32.inc
includelib masm32.lib

include kernel32.inc
includelib kernel32.lib

include user32.inc
includelib user32.lib

.code

;requires power > 0 for correct answers
pow proc x:DWORD, power:DWORD

    ;THESE TWO MOVES RIGHT HERE ARE NOT WORKING AS EXPECTED
    ;I PUSH 2 ONTO STACK BUT WHEN I LOOK AT REGISTER VALUES
    ;IN DEBUG THEY ARE INCORRECT/GARBAGE
    mov eax, x      ;eax has x
    mov edx, power  ;edx has power
    mov ecx, eax    ;ecx will be my constant base

start_power:
    cmp edx, 1      ;is power 1?
    je end_power    ;then jump to end
    imul eax, ecx   ;else mul result/x with x
    dec edx         ;power--
    jmp start_power ;jump back to beginning of loop

end_power:
    ret             ;return answer eax

pow endp

start:

invoke pow, 2, 2 ;eax should hold 4 after this
invoke ExitProcess, eax ;program should exit with code eax, ez way to print result

end start
</code>```

答:
Change the calling convention to c and it works, but I don't know why. If someone could explain that would be great.

With stdcall calling convention the callee cleans up the stack... and that's all I know. There must be more to it. The stack pointer could just carry on at whatever position after returning from the pow function and things should work correctly right?

Body:
I'm learning MASM and I can't get this simple code to work. I'm not getting the values I pass into invoke, I don't know what's happening. I've tried push 2, push 2, call pow. Same results. EAX and EDX look like garbage or maybe memory addresses.

The thread 0x1544 has exited with code -1073741510 (0xc000013a).
The thread 0xd8 has exited with code -1073741510 (0xc000013a).
The thread 0x898 has exited with code -1073741510 (0xc000013a).
The thread 0x21c4 has exited with code -1073741510 (0xc000013a).
The program '[2296] AssemblyTutorial.exe' has exited with code -1073741510 (0xc000013a).

This just means I closed the console window, but why are there 4 threads?

.386
.model flat,stdcall
option casemap:none

include windows.inc

include masm32.inc
includelib masm32.lib

include kernel32.inc
includelib kernel32.lib

include user32.inc
includelib user32.lib

.code

;requires power > 0 for correct answers
pow proc x:DWORD, power:DWORD

    ;THESE TWO MOVES RIGHT HERE ARE NOT WORKING AS EXPECTED
    ;I PUSH 2 ONTO STACK BUT WHEN I LOOK AT REGISTER VALUES
    ;IN DEBUG THEY ARE INCORRECT/GARBAGE
    mov eax, x      ;eax has x
    mov edx, power  ;edx has power
    mov ecx, eax    ;ecx will be my constant base

start_power:
    cmp edx, 1      ;is power 1?
    je end_power    ;then jump to end
    imul eax, ecx   ;else mul result/x with x
    dec edx         ;power--
    jmp start_power ;jump back to beginning of loop

end_power:
    ret             ;return answer eax

pow endp

start:

invoke pow, 2, 2 ;eax should hold 4 after this
invoke ExitProcess, eax ;program should exit with code eax, ez way to print result

end start


问:
Filter at multiple levels with GraphQL and Graphene
I'm using Django and Graphene and have multiple levels I'd like to filter on.  But I can't get past either "Unknown operation named \"undefined\"." or getting ALL objects at each level of the hierarchy (i.e.: ALL jobDetails for all jobs listed for EACH job).

I'm trying to do this query:

```<code>query {
  allPushes(revision: "1ef73669e8fccac35b650ff81df1b575a39a0fd5") {
    edges {
      node {
        revision
        author
        jobs (result: "testfailed") {
          edges {
            node {
              result
              jobDetails (url_Iendswith: "errorsummary.log") {
                edges {
                  node {
                    url
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
</code>```

In Django, jobDetails has a foreign key to jobs, which has a foreign key to pushes

My first attempt was to setup my nodes:

```<code>class JobDetailNode(DjangoObjectType):
    class Meta:
        model = JobDetail
        filter_fields = {
            'url': ('exact', 'icontains', 'iendswith')
        }
        interfaces = (relay.Node, )

class JobNode(DjangoObjectType):
    class Meta:
        model = Job
        filter_fields = ('result', 'tier')
        interfaces = (relay.Node, )

    job_details = DjangoFilterConnectionField(JobDetailNode)

class PushNode(DjangoObjectType):
    class Meta:
        model = Push
        filter_fields = ('revision', )
        interfaces = (relay.Node, )

    jobs = DjangoFilterConnectionField(JobNode)
</code>```

But this returns, as I said, all jobDetails at for EACH job, not just the jobDetails that belong to that job.

But if I remove those DjangoFilterConnectionField fields, then I can't filter at each level; just the first.

My Query looks like this:

```<code>class Query(ObjectType):
    all_pushes = DjangoFilterConnectionField(PushNode)
    all_jobs = DjangoFilterConnectionField(JobNode)
    all_job_details = DjangoFilterConnectionField(JobDetailNode)

    def resolve_all_pushes(self, args):
        return Push.objects.filter(**args)

    def resolve_all_jobs(self, args):
        return Job.objects.filter(**args)

    def resolve_all_job_details(self, args):
        return JobDetail.objects.filter(**args)
</code>```

Any suggestions on how to setup filtering at multiple levels like this?  Thanks in advance!!

答:
This is a bug in graphene-django. It was fixed in version 1.3.
Changelog

Regards.

Body:
I'm using Django and Graphene and have multiple levels I'd like to filter on.  But I can't get past either "Unknown operation named \"undefined\"." or getting ALL objects at each level of the hierarchy (i.e.: ALL jobDetails for all jobs listed for EACH job).

I'm trying to do this query:

query {
  allPushes(revision: "1ef73669e8fccac35b650ff81df1b575a39a0fd5") {
    edges {
      node {
        revision
        author
        jobs (result: "testfailed") {
          edges {
            node {
              result
              jobDetails (url_Iendswith: "errorsummary.log") {
                edges {
                  node {
                    url
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

In Django, jobDetails has a foreign key to jobs, which has a foreign key to pushes

My first attempt was to setup my nodes:

class JobDetailNode(DjangoObjectType):
    class Meta:
        model = JobDetail
        filter_fields = {
            'url': ('exact', 'icontains', 'iendswith')
        }
        interfaces = (relay.Node, )

class JobNode(DjangoObjectType):
    class Meta:
        model = Job
        filter_fields = ('result', 'tier')
        interfaces = (relay.Node, )

    job_details = DjangoFilterConnectionField(JobDetailNode)

class PushNode(DjangoObjectType):
    class Meta:
        model = Push
        filter_fields = ('revision', )
        interfaces = (relay.Node, )

    jobs = DjangoFilterConnectionField(JobNode)

But this returns, as I said, all jobDetails at for EACH job, not just the jobDetails that belong to that job.

But if I remove those DjangoFilterConnectionField fields, then I can't filter at each level; just the first.

My Query looks like this:

class Query(ObjectType):
    all_pushes = DjangoFilterConnectionField(PushNode)
    all_jobs = DjangoFilterConnectionField(JobNode)
    all_job_details = DjangoFilterConnectionField(JobDetailNode)

    def resolve_all_pushes(self, args):
        return Push.objects.filter(**args)

    def resolve_all_jobs(self, args):
        return Job.objects.filter(**args)

    def resolve_all_job_details(self, args):
        return JobDetail.objects.filter(**args)

Any suggestions on how to setup filtering at multiple levels like this?  Thanks in advance!!


问:
I am unable to get value from div tag
```<code><!DOCTYPE html>
<html>
<body>

<p>Write something in the text field to trigger a function.</p>

<div id="myInput" oninput="myFunction()" contenteditable>100</div>

<p id="demo"></p>

<script>
function myFunction() {
    var x = document.getElementById("myInput").value;
    document.getElementById("demo").innerHTML = "You wrote: " + x;
}
</script>

</body>
</html>
</code>```

Please give me some solution on this. In output i get value for x is "undefined".

答:
A div doesn't have a value property like a form input does. You need to get the HTML of the element with:

```<code>var x = document.getElementById("myInput").innerHTML;
</code>```

function myFunction() {
  var x = document.getElementById("myInput").innerHTML;
  document.getElementById("demo").innerHTML = "You wrote: " + x;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><p>Write something in the text field to trigger a function.</p>

<div id="myInput" oninput="myFunction()" contenteditable>100</div>

<p id="demo"></p></code>```

Title: I am unable to get value from div tag

Body:
<!DOCTYPE html>

Write something in the text field to trigger a function.

100

Please give me some solution on this. In output i get value for x is "undefined".

Body:
A div doesn't have a value property like a form input does. You need to get the HTML of the element with:

var x = document.getElementById("myInput").innerHTML;

function myFunction() {
  var x = document.getElementById("myInput").innerHTML;
  document.getElementById("demo").innerHTML = "You wrote: " + x;
}

<p>Write something in the text field to trigger a function.</p>

<div id="myInput" oninput="myFunction()" contenteditable>100</div>

<p id="demo"></p>


问:
'Syntax error: invalid syntax' pointing to a while loop
The console I use, pycripter, says that the line with the while in it is incorrect. I checked my other programs and it works there.  Am I missing something? The error message says 'Syntax Error: invalid syntax'.

```<code>import pygame, sys
from pygame.locals import *

pygame.init()

Display = pygame.display.set_mode((700, 500))

SquareLocation((350, 100), (400,

while True:
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()
    pygame.display.update()
</code>```

答: You left the previous line (before the while statement) unfinished. There is no other problem with the code segment you provided.</p>

Body:
The console I use, pycripter, says that the line with the while in it is incorrect. I checked my other programs and it works there.  Am I missing something? The error message says 'Syntax Error: invalid syntax'.

import pygame, sys
from pygame.locals import *

pygame.init()

Display = pygame.display.set_mode((700, 500))

SquareLocation((350, 100), (400,

while True:
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()
    pygame.display.update()


问:
onReceive in BroadcastReceiver triggers when app starts
I was making a sample and spotted that if i register receiver in code onReceive triggers when app starts. But if i register one in the context it doesn't Why?

```<code>Activity:
public class MainActivity extends AppCompatActivity {
private BroadcastReceiver mBroadcastReceiver;
private BroadcastReceiver mMessageReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        String message = intent.getExtras().getString("SomeString");
        Toast.makeText(MainActivity.this, message, Toast.LENGTH_SHORT).show();
    }
};

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}

@Override
protected void onResume() {
    super.onResume();
    mBroadcastReceiver = new SomeReceiver();
    registerReceiver(mBroadcastReceiver, new IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION));
    LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver,new IntentFilter("DanMan"));
}

@Override
protected void onPause() {
    super.onPause();
    unregisterReceiver(mBroadcastReceiver);
    LocalBroadcastManager.getInstance(this).unregisterReceiver(mMessageReceiver);
}
</code>```

}

Receiver:

```<code>public class SomeReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
    Log.d("receiver", "action :" + intent.getAction());
    intent.setAction("DanMan");
    LocalBroadcastManager.getInstance(context).sendBroadcast(intent.putExtra("SomeString", "Hello world!"));
}
</code>```

}

答:
Try to do this and let me know if it works or not

Just create a BroadcastReceiver Object before onCreate using

```<code>private BroadcastReceiver mMessageReceiver;
</code>```

Instantiate the register object in onCreate() using

```<code>mMessageReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        String message = intent.getExtras().getString("SomeString");
        Toast.makeText(MainActivity.this, message, Toast.LENGTH_SHORT).show();
    }
};
</code>```

Body:
I was making a sample and spotted that if i register receiver in code onReceive triggers when app starts. But if i register one in the context it doesn't Why?

Activity:
public class MainActivity extends AppCompatActivity {
private BroadcastReceiver mBroadcastReceiver;
private BroadcastReceiver mMessageReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        String message = intent.getExtras().getString("SomeString");
        Toast.makeText(MainActivity.this, message, Toast.LENGTH_SHORT).show();
    }
};

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}

@Override
protected void onResume() {
    super.onResume();
    mBroadcastReceiver = new SomeReceiver();
    registerReceiver(mBroadcastReceiver, new IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION));
    LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver,new IntentFilter("DanMan"));
}

@Override
protected void onPause() {
    super.onPause();
    unregisterReceiver(mBroadcastReceiver);
    LocalBroadcastManager.getInstance(this).unregisterReceiver(mMessageReceiver);
}

}

Receiver:

public class SomeReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
    Log.d("receiver", "action :" + intent.getAction());
    intent.setAction("DanMan");
    LocalBroadcastManager.getInstance(context).sendBroadcast(intent.putExtra("SomeString", "Hello world!"));
}

}

Body:
Try to do this and let me know if it works or not

Just create a BroadcastReceiver Object before onCreate using

private BroadcastReceiver mMessageReceiver;

Instantiate the register object in onCreate() using

mMessageReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        String message = intent.getExtras().getString("SomeString");
        Toast.makeText(MainActivity.this, message, Toast.LENGTH_SHORT).show();
    }
};


问:
Android Studio - All file names in project are red but there are no errors
I imported a ADT Project in Android Studio. I got a ton of errors, but I could fix them all. I don't think the "how" is important in this case, I wouldn't be able to recall all the errors anyways. The project runs now without errors, but somehow Android Studio marks all files red. Just the filenames, there are no errors in the code. I tried cleaning and restarting.

Did someone experience something like this before? Or maybe a related problem with IntelliJ someone could solve?

Edit:

It was the version control. The project was unversioned but in a SVN controlled folder. Thats what the red was indicating. A solution could be to copy the project to a different folder or to add the files to version control.

答: This happened to me every time I would set up a git repo in my project. To answer the question, simply add the problematic files to your VCS, "git add" in my case and you should be good to go.  </p>


问:
Video Element Error: MEDIA_ERR_SRC_NOT_SUPPORTED
I'm trying to play a dash mpd file with dash.js.I used axinom tutorial for guidance which suggested the command below for generating the mpd file.

```<code>mkdir dash_unprotected
MP4Box -dash 4000 -rap -frag-rap -sample-groups-traf -profile dashavc264:live
-bs-switching no -segment-name dash_$RepresentationID$_$Number$ -url-template
video-700k.mp4 video-1000k.mp4 video-1500k.mp4 video-2000k.mp4 audio.mp4 -out
"dash_unprotected/manifest.mpd"
</code>```

The resulting mpd file

```<code> <?xml version="1.0"?>
<!-- MPD file Generated with GPAC version 0.5.1-DEV-rev5619  on 2017-06-29T06:08:26Z-->
<MPD xmlns="urn:mpeg:dash:schema:mpd:2011" minBufferTime="PT1.500000S" type="static" mediaPresentationDuration="PT0H1M55.01S" profiles="urn:mpeg:dash:profile:isoff-live:2011, http://dashif.org/guildelines/dash264">
 <ProgramInformation moreInformationURL="http://gpac.sourceforge.net">
  <Title>dash_unprotected/manifest.mpd generated by GPAC</Title>
 </ProgramInformation>

 <Period duration="PT0H1M55.01S">
  <AdaptationSet segmentAlignment="true" maxWidth="316" maxHeight="576" maxFrameRate="30" par="316:576" lang="und">
   <SegmentTemplate timescale="15360" media="dash_dash_unprotected$$Number$.m4s" startNumber="1" duration="49009" initialization="dash_dash_unprotected$init.mp4"/>
   <Representation id="1" mimeType="video/mp4" codecs="avc1.64002a" width="158" height="288" frameRate="30" sar="396:395" startWithSAP="1" bandwidth="699969">
   </Representation>
   <Representation id="2" mimeType="video/mp4" codecs="avc1.64002a" width="198" height="360" frameRate="30" sar="1:1" startWithSAP="1" bandwidth="996926">
   </Representation>
   <Representation id="3" mimeType="video/mp4" codecs="avc1.64002a" width="264" height="480" frameRate="30" sar="1:1" startWithSAP="1" bandwidth="1496279">
   </Representation>
   <Representation id="4" mimeType="video/mp4" codecs="avc1.64002a" width="316" height="576" frameRate="30" sar="396:395" startWithSAP="1" bandwidth="1993448">
   </Representation>
  </AdaptationSet>
  <AdaptationSet segmentAlignment="true" lang="und">
   <SegmentTemplate timescale="44100" media="dash_dash_unprotected$$Number$.m4s" startNumber="1" duration="174856" initialization="dash_dash_unprotected$init.mp4"/>
   <Representation id="5" mimeType="audio/mp4" codecs="mp4a.40.2" audioSamplingRate="44100" startWithSAP="1" bandwidth="97798">
    <AudioChannelConfiguration schemeIdUri="urn:mpeg:dash:23003:3:audio_channel_configuration:2011" value="2"/>
   </Representation>
  </AdaptationSet>
 </Period>
</MPD>
</code>```

I then try to play it in dash.js using the JavaScript code below

```<code>    var url = "drm/dash_unprotected/manifest.mpd";
    var player = dashjs.MediaPlayer().create();

$(function() {
    player.initialize(document.querySelector("#videoPlayer"),null, true);
    player.attachVideoContainer(document.getElementById("videoContainer"));

    $('#playButton').click(function() {
        player.attachSource(url);
    });
});
</code>```

But dash.js throws an error

```<code>[42585] Video Element Error: MEDIA_ERR_SRC_NOT_SUPPORTED (CHUNK_DEMUXER_ERROR_APPEND_FAILED: audio object type 0x40 does not match what is specified in the mimetype.)
dash.all.debug.js:14793 [42586] [object MediaError]
dash.all.debug.js:14793 [42588] Schedule controller stopping for video
dash.all.debug.js:14793 [42589] Schedule controller stopping for audio
dash.all.debug.js:14793 [42591] Caught pending play exception - continuing (NotSupportedError: Failed to load because no supported source was found.)
</code>```

How can i solve this error? I'm new to dash.js and mpeg-dash staff

答:
I was able to solve the error by just removing the -segment-name option and it's value. So my command look like this

```<code> mkdir dash_unprotected
MP4Box -dash 4000 -rap -frag-rap -sample-groups-traf -profile dashavc264:live
-bs-switching no -url-template
video-700k.mp4 video-1000k.mp4 video-1500k.mp4 video-2000k.mp4 audio.mp4 -out
"dash_unprotected/manifest.mpd"
</code>```

-segment-name option was making my segments to overwrite each other. e.g video segments to be overwritten by audio segments.
Overwriting was happening because both video and audio segments were being given the same names even when i use unique values to the -segment-name option.

-segment-name $RepresentationID$$ or -segment-name $Time$$

Eliminating this option make MP4Box to use the default value %s_dash for -segment-name. So audio segments will be named like this

```<code> audio_dash1.m4s
</code>```

and video segments like this

```<code> `video_dash1.m4s`
</code>```

Body:
I'm trying to play a dash mpd file with dash.js.I used axinom tutorial for guidance which suggested the command below for generating the mpd file.

mkdir dash_unprotected
MP4Box -dash 4000 -rap -frag-rap -sample-groups-traf -profile dashavc264:live
-bs-switching no -segment-name dash_$RepresentationID$_$Number$ -url-template
video-700k.mp4 video-1000k.mp4 video-1500k.mp4 video-2000k.mp4 audio.mp4 -out
"dash_unprotected/manifest.mpd"

The resulting mpd file

 <?xml version="1.0"?>

<MPD xmlns="urn:mpeg:dash:schema:mpd:2011" minBufferTime="PT1.500000S" type="static" mediaPresentationDuration="PT0H1M55.01S" profiles="urn:mpeg:dash:profile:isoff-live:2011, http://dashif.org/guildelines/dash264">
 <ProgramInformation moreInformationURL="http://gpac.sourceforge.net">
  <Title>dash_unprotected/manifest.mpd generated by GPAC</Title>
 </ProgramInformation>

 <Period duration="PT0H1M55.01S">
  <AdaptationSet segmentAlignment="true" maxWidth="316" maxHeight="576" maxFrameRate="30" par="316:576" lang="und">
   <SegmentTemplate timescale="15360" media="dash_dash_unprotected$$Number$.m4s" startNumber="1" duration="49009" initialization="dash_dash_unprotected$init.mp4"/>
   <Representation id="1" mimeType="video/mp4" codecs="avc1.64002a" width="158" height="288" frameRate="30" sar="396:395" startWithSAP="1" bandwidth="699969">
   </Representation>
   <Representation id="2" mimeType="video/mp4" codecs="avc1.64002a" width="198" height="360" frameRate="30" sar="1:1" startWithSAP="1" bandwidth="996926">
   </Representation>
   <Representation id="3" mimeType="video/mp4" codecs="avc1.64002a" width="264" height="480" frameRate="30" sar="1:1" startWithSAP="1" bandwidth="1496279">
   </Representation>
   <Representation id="4" mimeType="video/mp4" codecs="avc1.64002a" width="316" height="576" frameRate="30" sar="396:395" startWithSAP="1" bandwidth="1993448">
   </Representation>
  </AdaptationSet>
  <AdaptationSet segmentAlignment="true" lang="und">
   <SegmentTemplate timescale="44100" media="dash_dash_unprotected$$Number$.m4s" startNumber="1" duration="174856" initialization="dash_dash_unprotected$init.mp4"/>
   <Representation id="5" mimeType="audio/mp4" codecs="mp4a.40.2" audioSamplingRate="44100" startWithSAP="1" bandwidth="97798">
    <AudioChannelConfiguration schemeIdUri="urn:mpeg:dash:23003:3:audio_channel_configuration:2011" value="2"/>
   </Representation>
  </AdaptationSet>
 </Period>
</MPD>

I then try to play it in dash.js using the JavaScript code below

    var url = "drm/dash_unprotected/manifest.mpd";
    var player = dashjs.MediaPlayer().create();

$(function() {
    player.initialize(document.querySelector("#videoPlayer"),null, true);
    player.attachVideoContainer(document.getElementById("videoContainer"));

    $('#playButton').click(function() {
        player.attachSource(url);
    });
});

But dash.js throws an error

[42585] Video Element Error: MEDIA_ERR_SRC_NOT_SUPPORTED (CHUNK_DEMUXER_ERROR_APPEND_FAILED: audio object type 0x40 does not match what is specified in the mimetype.)
dash.all.debug.js:14793 [42586] [object MediaError]
dash.all.debug.js:14793 [42588] Schedule controller stopping for video
dash.all.debug.js:14793 [42589] Schedule controller stopping for audio
dash.all.debug.js:14793 [42591] Caught pending play exception - continuing (NotSupportedError: Failed to load because no supported source was found.)

How can i solve this error? I'm new to dash.js and mpeg-dash staff

Body:
I was able to solve the error by just removing the -segment-name option and it's value. So my command look like this

 mkdir dash_unprotected
MP4Box -dash 4000 -rap -frag-rap -sample-groups-traf -profile dashavc264:live
-bs-switching no -url-template
video-700k.mp4 video-1000k.mp4 video-1500k.mp4 video-2000k.mp4 audio.mp4 -out
"dash_unprotected/manifest.mpd"

-segment-name option was making my segments to overwrite each other. e.g video segments to be overwritten by audio segments.
Overwriting was happening because both video and audio segments were being given the same names even when i use unique values to the -segment-name option.

-segment-name $RepresentationID$$ or -segment-name $Time$$

Eliminating this option make MP4Box to use the default value %s_dash for -segment-name. So audio segments will be named like this

 audio_dash1.m4s

and video segments like this

 `video_dash1.m4s`


问:
Suggestions for speeding up LEFT JOIN in MySQL
I have a tabled named usr_data with 40,000 or so records that I want to left join with the user's organization data (roughly 1000 records) via a select in a join, obviously this is really slow (up to 150 seconds).

I was wondering if there were any ways to speed this up? Unfortunately this is the speediest query for the sub-select in the join.

My Query

```<code>    SELECT  usr_data.usr_id,usr_data.login,orgus.title FROM usr_data
    LEFT JOIN (
        SELECT object_reference.ref_id,rbac_ua.usr_id,object_data.obj_id,object_data.title
        FROM rbac_ua
        JOIN rbac_fa ON rbac_fa.rol_id = rbac_ua.rol_id
        JOIN object_reference ON rbac_fa.parent = object_reference.ref_id
        JOIN object_data ON object_data.obj_id = object_reference.obj_id
        JOIN object_data role ON role.obj_id = rbac_ua.rol_id
        WHERE object_data.type = 'orgu') as orgus on orgus.usr_id = usr_data.usr_id
    WHERE usr_data.usr_id > 0 AND usr_data.login <> "anonymous"
</code>```

Describe of Query

```<code>+------+-------------+------------------+--------+-----------------------+---------+---------+--------------------------------+------+--------------------------+
| id   | select_type | table            | type   | possible_keys         | key     | key_len | ref                            | rows | Extra                    |
+------+-------------+------------------+--------+-----------------------+---------+---------+--------------------------------+------+--------------------------+
|    1 | SIMPLE      | usr_data         | range  | PRIMARY,i1_idx        | PRIMARY | 4       | NULL                           | 8148 | Using where              |
|    1 | SIMPLE      | rbac_ua          | ref    | PRIMARY,i1_idx,i2_idx | PRIMARY | 4       | ildCPC.usr_data.usr_id         |    2 | Using where; Using index |
|    1 | SIMPLE      | rbac_fa          | ref    | PRIMARY,i1_idx        | PRIMARY | 4       | ildCPC.rbac_ua.rol_id          |    1 | Using where; Using index |
|    1 | SIMPLE      | role             | eq_ref | PRIMARY               | PRIMARY | 4       | ildCPC.rbac_ua.rol_id          |    1 | Using index              |
|    1 | SIMPLE      | object_reference | eq_ref | PRIMARY,i1_idx        | PRIMARY | 4       | ildCPC.rbac_fa.parent          |    1 | Using where              |
|    1 | SIMPLE      | object_data      | eq_ref | PRIMARY,i1_idx        | PRIMARY | 4       | ildCPC.object_reference.obj_id |    1 | Using where              |
+------+-------------+------------------+--------+-----------------------+---------+---------+--------------------------------+------+--------------------------+
</code>```

usr_data table

```<code>+----------------------+---------------+------+-----+---------+-------+
| Field                | Type          | Null | Key | Default | Extra |
+----------------------+---------------+------+-----+---------+-------+
| usr_id               | int(11)       | NO   | PRI | 0       |       |
| login                | varchar(80)   | YES  | MUL | NULL    |       |
| passwd               | varchar(80)   | YES  |     | NULL    |       |
| firstname            | varchar(32)   | YES  |     | NULL    |       |
| lastname             | varchar(32)   | YES  |     | NULL    |       |
| title                | varchar(32)   | YES  |     | NULL    |       |
| gender               | char(1)       | YES  |     | m       |       |
| email                | varchar(80)   | YES  |     | NULL    |       |
</code>```

usr_data indexes

```<code>+----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table    | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| usr_data |          0 | PRIMARY  |            1 | usr_id      | A         |       29354 |     NULL | NULL   |      | BTREE      |         |               |
| usr_data |          1 | i1_idx   |            1 | login       | A         |       29354 |     NULL | NULL   | YES  | BTREE      |         |               |
| usr_data |          1 | i1_idx   |            2 | passwd      | A         |       29354 |     NULL | NULL   | YES  | BTREE      |         |               |
| usr_data |          1 | i2_idx   |            1 | ext_account | A         |           2 |     NULL | NULL   | YES  | BTREE      |         |               |
| usr_data |          1 | i2_idx   |            2 | auth_mode   | A         |           4 |     NULL | NULL   | YES  | BTREE      |         |               |
+----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
</code>```

I've tried to make a temp-table for that SELECT in the LEFT JOIN but it didn't really speed it up any, the query takes up to 150 seconds currently, with a right join it brings it down to about 1 second. (It's the smaller table).

```<code>select * from object_data where type = 'orgu' returns 1058 rows.
</code>```

SHOW CREATE TABLE rbac_ua

```<code>+---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table   | Create Table                                                                                |
+---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| rbac_ua | CREATE TABLE `rbac_ua` (
  `usr_id` int(11) NOT NULL DEFAULT '0',
  `rol_id` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`usr_id`,`rol_id`),
  KEY `i1_idx` (`usr_id`),
  KEY `i2_idx` (`rol_id`),
  KEY `rol_id` (`rol_id`,`usr_id`),
  KEY `rol_usr` (`rol_id`,`usr_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=DYNAMIC |
+---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
</code>```

SHOW CREATE TABLE rbac_fa

```<code>+---------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table   | Create Table                                                                                |
+---------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| rbac_fa | CREATE TABLE `rbac_fa` (
  `rol_id` int(11) NOT NULL DEFAULT '0',
  `parent` int(11) NOT NULL DEFAULT '0',
  `assign` char(1) COLLATE utf8_unicode_ci DEFAULT NULL,
  `protected` char(1) COLLATE utf8_unicode_ci DEFAULT 'n',
  PRIMARY KEY (`rol_id`,`parent`),
  KEY `i1_idx` (`parent`),
  KEY `parent` (`parent`,`rol_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=DYNAMIC |
+---------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
</code>```

SHOW CREATE TABLE object_data

```<code>+-------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table       | Create Table                                                                                |
+-------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| object_data | CREATE TABLE `object_data` (
  `obj_id` int(11) NOT NULL DEFAULT '0',
  `type` char(4) COLLATE utf8_unicode_ci DEFAULT 'none',
  `title` char(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `description` char(128) COLLATE utf8_unicode_ci DEFAULT NULL,
  `owner` int(11) NOT NULL DEFAULT '0',
  `create_date` datetime DEFAULT NULL,
  `last_update` datetime DEFAULT NULL,
  `import_id` char(50) COLLATE utf8_unicode_ci DEFAULT NULL,
  PRIMARY KEY (`obj_id`),
  KEY `i1_idx` (`type`),
  KEY `i2_idx` (`title`),
  KEY `i4_idx` (`import_id`),
  FULLTEXT KEY `i3_idx` (`title`,`description`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=DYNAMIC |
+-------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
</code>```

SHOW CREATE TABLE object_reference

```<code>+------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table            | Create Table                                                                                |
+------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| object_reference | CREATE TABLE `object_reference` (
  `ref_id` int(11) NOT NULL DEFAULT '0',
  `obj_id` int(11) NOT NULL DEFAULT '0',
  `deleted` datetime DEFAULT NULL,
  PRIMARY KEY (`ref_id`),
  KEY `i1_idx` (`obj_id`),
  KEY `i2_idx` (`deleted`),
  KEY `obj_id` (`obj_id`,`ref_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=DYNAMIC |
+------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
</code>```

If i'm missing any useful information, please let me know.

Thanks in Advance.

答:
By removing the subselect and using joins, you should be able to improve the performance. The subselect is processed first, generating a temp table, which is quite a performance hit.</p>

```<code>SELECT
    usr_data.usr_id,
    usr_data.login,
    object_data.title,
    object_reference.ref_id,
    rbac_ua.usr_id,
    object_data.obj_id,
    object_data.title
FROM usr_data
LEFT JOIN rbac_ua
ON rbac_ua.usr_id = usr_data.usr_id
JOIN rbac_fa ON rbac_fa.rol_id = rbac_ua.rol_id
JOIN object_reference ON rbac_fa.parent = object_reference.ref_id
JOIN object_data ON object_data.obj_id = object_reference.obj_id
JOIN object_data role ON role.obj_id = rbac_ua.rol_id
WHERE
    object_data.type = 'orgu' AND
    usr_data.usr_id > 0 AND
    usr_data.login <> "anonymous"
</code>```

Body:
I have a tabled named usr_data with 40,000 or so records that I want to left join with the user's organization data (roughly 1000 records) via a select in a join, obviously this is really slow (up to 150 seconds).

I was wondering if there were any ways to speed this up? Unfortunately this is the speediest query for the sub-select in the join.

My Query

    SELECT  usr_data.usr_id,usr_data.login,orgus.title FROM usr_data
    LEFT JOIN (
        SELECT object_reference.ref_id,rbac_ua.usr_id,object_data.obj_id,object_data.title
        FROM rbac_ua
        JOIN rbac_fa ON rbac_fa.rol_id = rbac_ua.rol_id
        JOIN object_reference ON rbac_fa.parent = object_reference.ref_id
        JOIN object_data ON object_data.obj_id = object_reference.obj_id
        JOIN object_data role ON role.obj_id = rbac_ua.rol_id
        WHERE object_data.type = 'orgu') as orgus on orgus.usr_id = usr_data.usr_id
    WHERE usr_data.usr_id > 0 AND usr_data.login <> "anonymous"

Describe of Query

+------+-------------+------------------+--------+-----------------------+---------+---------+--------------------------------+------+--------------------------+
| id   | select_type | table            | type   | possible_keys         | key     | key_len | ref                            | rows | Extra                    |
+------+-------------+------------------+--------+-----------------------+---------+---------+--------------------------------+------+--------------------------+
|    1 | SIMPLE      | usr_data         | range  | PRIMARY,i1_idx        | PRIMARY | 4       | NULL                           | 8148 | Using where              |
|    1 | SIMPLE      | rbac_ua          | ref    | PRIMARY,i1_idx,i2_idx | PRIMARY | 4       | ildCPC.usr_data.usr_id         |    2 | Using where; Using index |
|    1 | SIMPLE      | rbac_fa          | ref    | PRIMARY,i1_idx        | PRIMARY | 4       | ildCPC.rbac_ua.rol_id          |    1 | Using where; Using index |
|    1 | SIMPLE      | role             | eq_ref | PRIMARY               | PRIMARY | 4       | ildCPC.rbac_ua.rol_id          |    1 | Using index              |
|    1 | SIMPLE      | object_reference | eq_ref | PRIMARY,i1_idx        | PRIMARY | 4       | ildCPC.rbac_fa.parent          |    1 | Using where              |
|    1 | SIMPLE      | object_data      | eq_ref | PRIMARY,i1_idx        | PRIMARY | 4       | ildCPC.object_reference.obj_id |    1 | Using where              |
+------+-------------+------------------+--------+-----------------------+---------+---------+--------------------------------+------+--------------------------+

usr_data table

+----------------------+---------------+------+-----+---------+-------+
| Field                | Type          | Null | Key | Default | Extra |
+----------------------+---------------+------+-----+---------+-------+
| usr_id               | int(11)       | NO   | PRI | 0       |       |
| login                | varchar(80)   | YES  | MUL | NULL    |       |
| passwd               | varchar(80)   | YES  |     | NULL    |       |
| firstname            | varchar(32)   | YES  |     | NULL    |       |
| lastname             | varchar(32)   | YES  |     | NULL    |       |
| title                | varchar(32)   | YES  |     | NULL    |       |
| gender               | char(1)       | YES  |     | m       |       |
| email                | varchar(80)   | YES  |     | NULL    |       |

usr_data indexes

+----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table    | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| usr_data |          0 | PRIMARY  |            1 | usr_id      | A         |       29354 |     NULL | NULL   |      | BTREE      |         |               |
| usr_data |          1 | i1_idx   |            1 | login       | A         |       29354 |     NULL | NULL   | YES  | BTREE      |         |               |
| usr_data |          1 | i1_idx   |            2 | passwd      | A         |       29354 |     NULL | NULL   | YES  | BTREE      |         |               |
| usr_data |          1 | i2_idx   |            1 | ext_account | A         |           2 |     NULL | NULL   | YES  | BTREE      |         |               |
| usr_data |          1 | i2_idx   |            2 | auth_mode   | A         |           4 |     NULL | NULL   | YES  | BTREE      |         |               |
+----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+

I've tried to make a temp-table for that SELECT in the LEFT JOIN but it didn't really speed it up any, the query takes up to 150 seconds currently, with a right join it brings it down to about 1 second. (It's the smaller table).

select * from object_data where type = 'orgu' returns 1058 rows.

SHOW CREATE TABLE rbac_ua

+---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table   | Create Table                                                                                |
+---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| rbac_ua | CREATE TABLE `rbac_ua` (
  `usr_id` int(11) NOT NULL DEFAULT '0',
  `rol_id` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`usr_id`,`rol_id`),
  KEY `i1_idx` (`usr_id`),
  KEY `i2_idx` (`rol_id`),
  KEY `rol_id` (`rol_id`,`usr_id`),
  KEY `rol_usr` (`rol_id`,`usr_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=DYNAMIC |
+---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

SHOW CREATE TABLE rbac_fa

+---------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table   | Create Table                                                                                |
+---------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| rbac_fa | CREATE TABLE `rbac_fa` (
  `rol_id` int(11) NOT NULL DEFAULT '0',
  `parent` int(11) NOT NULL DEFAULT '0',
  `assign` char(1) COLLATE utf8_unicode_ci DEFAULT NULL,
  `protected` char(1) COLLATE utf8_unicode_ci DEFAULT 'n',
  PRIMARY KEY (`rol_id`,`parent`),
  KEY `i1_idx` (`parent`),
  KEY `parent` (`parent`,`rol_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=DYNAMIC |
+---------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

SHOW CREATE TABLE object_data

+-------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table       | Create Table                                                                                |
+-------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| object_data | CREATE TABLE `object_data` (
  `obj_id` int(11) NOT NULL DEFAULT '0',
  `type` char(4) COLLATE utf8_unicode_ci DEFAULT 'none',
  `title` char(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `description` char(128) COLLATE utf8_unicode_ci DEFAULT NULL,
  `owner` int(11) NOT NULL DEFAULT '0',
  `create_date` datetime DEFAULT NULL,
  `last_update` datetime DEFAULT NULL,
  `import_id` char(50) COLLATE utf8_unicode_ci DEFAULT NULL,
  PRIMARY KEY (`obj_id`),
  KEY `i1_idx` (`type`),
  KEY `i2_idx` (`title`),
  KEY `i4_idx` (`import_id`),
  FULLTEXT KEY `i3_idx` (`title`,`description`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=DYNAMIC |
+-------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

SHOW CREATE TABLE object_reference

+------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table            | Create Table                                                                                |
+------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| object_reference | CREATE TABLE `object_reference` (
  `ref_id` int(11) NOT NULL DEFAULT '0',
  `obj_id` int(11) NOT NULL DEFAULT '0',
  `deleted` datetime DEFAULT NULL,
  PRIMARY KEY (`ref_id`),
  KEY `i1_idx` (`obj_id`),
  KEY `i2_idx` (`deleted`),
  KEY `obj_id` (`obj_id`,`ref_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=DYNAMIC |
+------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

If i'm missing any useful information, please let me know.

Thanks in Advance.

Body:
By removing the subselect and using joins, you should be able to improve the performance. The subselect is processed first, generating a temp table, which is quite a performance hit.

SELECT
    usr_data.usr_id,
    usr_data.login,
    object_data.title,
    object_reference.ref_id,
    rbac_ua.usr_id,
    object_data.obj_id,
    object_data.title
FROM usr_data
LEFT JOIN rbac_ua
ON rbac_ua.usr_id = usr_data.usr_id
JOIN rbac_fa ON rbac_fa.rol_id = rbac_ua.rol_id
JOIN object_reference ON rbac_fa.parent = object_reference.ref_id
JOIN object_data ON object_data.obj_id = object_reference.obj_id
JOIN object_data role ON role.obj_id = rbac_ua.rol_id
WHERE
    object_data.type = 'orgu' AND
    usr_data.usr_id > 0 AND
    usr_data.login <> "anonymous"