database - MySQL Workbench 1146 error with table alias -


i have code of mysql in workbench

1. select `ΟΝΟΜΑΣΙΑ_ΠΡΟΪΟΝΤΟΣ`, `ΠΩΛΗΣΗ` 2. from(select `ΟΝΟΜΑΣΙΑ_ΠΡΟΪΟΝΤΟΣ`, sum(`ΠΟΣΟΤΗΤΑ`) `ΠΩΛΗΣΕΙΣ` 3. `hospital`.`προιοντα`, `hospital`.`χρεωσεις_περιστατικων` 4. `hospital`.`προιοντα`.`ΚΩΔΙΚΟΣ_ΠΡΟΪΟΝΤΟΣ` = `hospital`.`χρεωσεις_περιστατικων`.`ΚΩΔΙΚΟΣ_ΠΡΟΪΟΝΤΟΣ` , year(`ΗΜ_ΝΙΑ_ΧΡΕΩΣΗΣ`) = 2013 5. group `ΟΝΟΜΑΣΙΑ_ΠΡΟΪΟΝΤΟΣ`) `Π` 6. `ΠΩΛΗΣΗ` = (select max(`ΠΩΛΗΣΕΙΣ`) `Π`.`ΠΩΛΗΣΕΙΣ`); 

the problem exists in line 6. mysql workbench doesn't recognize table alias "Π", throws me error:

error code: 1146. table 'π.πωλησεισ' doesn't exist.

what can do?

that's because Π derived table , not permanent table , can't use in where clause normal table. rather include max() calculation in outer query. change query below

  select `ΟΝΟΜΑΣΙΑ_ΠΡΟΪΟΝΤΟΣ`, `ΠΩΛΗΣΗ`        (     select `ΟΝΟΜΑΣΙΑ_ΠΡΟΪΟΝΤΟΣ`,      `ΠΩΛΗΣΗ`,     sum(`ΠΟΣΟΤΗΤΑ`) `ΠΩΛΗΣΕΙΣ`      `hospital`.`προιοντα`, `hospital`.`χρεωσεις_περιστατικων`      `hospital`.`προιοντα`.`ΚΩΔΙΚΟΣ_ΠΡΟΪΟΝΤΟΣ` =      `hospital`.`χρεωσεις_περιστατικων`.`ΚΩΔΙΚΟΣ_ΠΡΟΪΟΝΤΟΣ`       , year(`ΗΜ_ΝΙΑ_ΧΡΕΩΣΗΣ`) = 2013      group `ΟΝΟΜΑΣΙΑ_ΠΡΟΪΟΝΤΟΣ`      having `ΠΩΛΗΣΗ` = max(`ΠΩΛΗΣΕΙΣ`)     ) `Π`; 

ps: btw, didn't knew mysql works in alien language well.


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -