MySQL Cannot create view for subquery in from clause -


i'm trying make query display top 10 systems , 'other' 11th row. made union query. found query build returns 'other' record each system name not in top10, made select in select sum 'other's. leading me error code 1349. me rearrange query?

create view queryview (select  system, cast(sum(duration) unsigned) 'sum' tbl_events     inner join (trans_gu, tbl_g, trans_gm) on (trans_gu.unit_id = tbl_events.unit_id     , trans_gu.gib_sn = tbl_g.sn     , tbl_g.equipcode = trans_gm.equipcode     , tbl_g.gen_model = trans_gm.gen_model) trans_gm.productline = 'fleet' group system order sum desc limit 10)  union  (select 'other' system, cast(sum(a.`sum`) unsigned) 'sum' (select  'other' system, sum(duration) 'sum'    tbl_events     inner join (trans_gu, tbl_g, trans_gm) on (trans_gu.unit_id = tbl_events.unit_id     , trans_gu.gib_sn = tbl_g.sn     , tbl_g.equipcode = trans_gm.equipcode     , tbl_g.gen_model = trans_gm.gen_model) trans_gm.productline = 'fleet' group system order sum desc limit 10,99999999) a); 

correct. mysql not support subqueries in from clauses. can rewrite second part of query without subquery:

(select 'other', cast(sum(duration) unisgned) "sum"   tbl_events inner join       (trans_gu, tbl_g, trans_gm)       on (trans_gu.unit_id = tbl_events.unit_id           , trans_gu.gib_sn = tbl_g.sn           , tbl_g.equipcode = trans_gm.equipcode           , tbl_g.gen_model = trans_gm.gen_model)  trans_gm.productline = 'fleet'  tbl_ram  group system  order sum desc  limit 10,99999999 )  

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -