问题
I'm wondering if it is possible to return a result set with column names which are stored in a separate table. Is this possible or do I need a stored_procedure with variables. See link for mysql_dump and description of required resultset:
http://pastie.org/584865
回答1:
You'd have to use a stored procedure that'd generate SQL dynamically and then run it. Column names aren't really first-class data in SQL, so you can't do much anything with them. They are determined at query parse time, before executing the query or fetching any data.
I suggest doing it in your app instead. Just have your app display/save/whatever the correct names instead of the database column names.
PS: You are abusing the relational model horribly. Please very carefully consider if you really want that schema. Your schema fails the first normal form. And what is worksheet_type_lookup
for? Doesn't worksheets
tell you which type?
来源:https://stackoverflow.com/questions/1281520/mysql-use-column-names-from-another-table