1

DESCRIBE(或 SHOW COLUMNS)除了表格之外似乎不起作用。

我希望能够检索 DESCRIBE 的等价物<table>,但是对于任意复杂的SELECT查询。

例如,我想说:

DESCRIBE (arbitrary SELECT statement) AS表2

SELECT语句可能包含 JOIN 等的位置

在最简单的情况下

 DESCRIBE (SELECT * from table1) as table2

应该产生相同的结果

 DESCRIBE table1

是否有一些 SQL 可以用来获取它,或者类似的东西?

4

1 回答 1

0

I'm assuming you are working with MySQL (Although this should work anyway). As of version 5.0.1, the DESCRIBE statement also works for views (http://dev.mysql.com/doc/refman/5.0/en/describe.html). Therefore, what you need to do is save your SELECT query as a view and execute a describe on the view:

CREATE VIEW myview AS SELECT qty, price, qty*price AS value FROM mytable;
DESCRIBE myview
于 2013-01-23T07:53:46.390 回答