B****s 发帖数: 5731 | 1 比如我不知道column name,只是要query第一或第二个column的全部value?
thanks
我用的事mysql | c*****d 发帖数: 6045 | 2 no
【在 B****s 的大作中提到】 : 比如我不知道column name,只是要query第一或第二个column的全部value? : thanks : 我用的事mysql
| B****s 发帖数: 5731 | | B*****g 发帖数: 34098 | 4 能问一下你要这个干嘛用吗?
【在 B****s 的大作中提到】 : haoba ,泪奔
| B****s 发帖数: 5731 | 5 我这里有些表是对日,月,年等不同时间段的统计,有些字段虽然名字不一样,但是表
的总体结构一样。
【在 B*****g 的大作中提到】 : 能问一下你要这个干嘛用吗?
| c*****d 发帖数: 6045 | 6 比如说每个table都有如下类似字段
tableA: yearA, monA, dateA, otherA
tableB: yearB, monB, dateB, otherB
。。。。
tableZ: yearZ, monZ, dateZ, otherZ
你想写一个sql语句,完成下面的功能,是吗?
select yearA, monA, dateA from tableA;
select yearB, monB, dateB from tableB;
。。。。
select yearZ, monZ, dateZ from tableZ;
【在 B****s 的大作中提到】 : 我这里有些表是对日,月,年等不同时间段的统计,有些字段虽然名字不一样,但是表 : 的总体结构一样。
| B*****g 发帖数: 34098 | 7 似乎他说column的名字不可知,只知道第一列是年,第二列是月,第三列是日.
【在 c*****d 的大作中提到】 : 比如说每个table都有如下类似字段 : tableA: yearA, monA, dateA, otherA : tableB: yearB, monB, dateB, otherB : 。。。。 : tableZ: yearZ, monZ, dateZ, otherZ : 你想写一个sql语句,完成下面的功能,是吗? : select yearA, monA, dateA from tableA; : select yearB, monB, dateB from tableB; : 。。。。 : select yearZ, monZ, dateZ from tableZ;
| c*****t 发帖数: 1879 | 8 select * 的话你取头几个 column 就是了。另外,可以查该 database 的
catalog 里的 table 得到该 table 的 schema 。
【在 B****s 的大作中提到】 : 我这里有些表是对日,月,年等不同时间段的统计,有些字段虽然名字不一样,但是表 : 的总体结构一样。
| c*****d 发帖数: 6045 | 9 en, 比如说每个table都有如下类似字段,但是名字没有规则
tableA: yearAA, AmonA, dateA, otherA
tableB: yearB, monBBBB, dateBB, otherB
。。。。
tableZ: yearZ, monZZ, dateZZZ, otherZ
你想完成下面的功能
select yearAA, AmonA, dateA from tableA;
select yearB, monBBBB, dateBB from tableB;
。。。。
select yearZ, monZZ, dateZZZ from tableZ;
在information_schema.columns中有字段位置,字段名字,表名
用sql语句把他们拼起来
【在 B*****g 的大作中提到】 : 似乎他说column的名字不可知,只知道第一列是年,第二列是月,第三列是日.
| c*****d 发帖数: 6045 | 10 select
concat('select ',GROUP_CONCAT(column_name),' from ',table_name, ';')
from
information_schema.columns
where
table_schema='X'
and
ORDINAL_POSITION <=3
and
table_name LIKE 'Y'
group by
table_name;
【在 c*****d 的大作中提到】 : en, 比如说每个table都有如下类似字段,但是名字没有规则 : tableA: yearAA, AmonA, dateA, otherA : tableB: yearB, monBBBB, dateBB, otherB : 。。。。 : tableZ: yearZ, monZZ, dateZZZ, otherZ : 你想完成下面的功能 : select yearAA, AmonA, dateA from tableA; : select yearB, monBBBB, dateBB from tableB; : 。。。。 : select yearZ, monZZ, dateZZZ from tableZ;
| B*****g 发帖数: 34098 | 11 你这个只能搞出sql,不能直接run。
Oracle PLSQL似乎搞不出来前N个(N是parameter),不知道把java搞上能不能行。
【在 c*****d 的大作中提到】 : select : concat('select ',GROUP_CONCAT(column_name),' from ',table_name, ';') : from : information_schema.columns : where : table_schema='X' : and : ORDINAL_POSITION <=3 : and : table_name LIKE 'Y'
| c*****d 发帖数: 6045 | 12 这个已经很简便了
直接run搞出的sql就行了
【在 B*****g 的大作中提到】 : 你这个只能搞出sql,不能直接run。 : Oracle PLSQL似乎搞不出来前N个(N是parameter),不知道把java搞上能不能行。
|
|