#!/bin/sh
max_length=0
for table_name in `cat tables`
do
current_length=$(echo ${table_name}|wc -c)
if [ ${current_length} -gt ${max_length} ]
then
max_length=${current_length}
fi
done
max_length=$((${max_length}-1))
printf "select *
"
printf "from (
"
cat tables|while read table_name
do
printf " select '%-${max_length}s' as table_name,count(1) as cnt from %-${max_length}s union all
" ${table_name} ${table_name}
done
printf " select '%-${max_length}s' as table_name,count(1) as cnt
" "invaild_column"
printf ") t1
"
printf "where table_name <> 'invaild_column'
"
printf "order by table_name
"
printf ";
"
select *
from (
select 'table_01 ' as table_name,count(1) as cnt from table_01 union all
select 'table_02 ' as table_name,count(1) as cnt from table_02 union all
select 'table_03 ' as table_name,count(1) as cnt from table_03 union all
select 'invalid_column' as table_name,count(1) as cnt
) t1
where table_name <> 'invalid_column'
order by table_name
;