select name from (select table_name from information_schema.columns where column_name='attr6') as t where attr6=1000;不加as t会报错,但是加了之后完全偏离了我的本意。加了as t之后,等于从关系表t中查找元组了。而我本来的意思是从所有包含attr6属性的关系表中找到attr6=1000的元组。要怎么才能实现这个要求呢?SQLselectMysql

解决方案 »

  1.   

    打开
    select table_name from information_schema.columns where column_name='attr6'
    游标,循环取值,字符串累加生成SQL语句,再动态执行类似select name from (从游标中取出的table_name) where attr6=1000
      

  2.   

    只能去系统表里面查询哪些表有attr6属性  然后找到这些表  去找寻attr6=1000的
      

  3.   

    只能先通过 select table_name from information_schema.columns where column_name='attr6' 得到相关表名,然后再生成查询语句去各表中找attr6=1000的记录。没有办法在一条SQL语句中实现。
      

  4.   

    select table_name INTO OUTFILE 'r:/temp/123.txt' from information_schema.columns where column_name='attr6'在EXCEL中编辑123.txt,在单元格中用公式生成
    " select name from " & a1 & " where attr6=1000"
    假设table_name在A1单元格再COPY到MYSQL中执行