zoukankan      html  css  js  c++  java
  • 多表select count语句生成 带格式化

    #!/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
    ;
    
  • 相关阅读:
    mac重启nginx时报nginx.pid不存在的解决办法
    js 正则表达式
    js 闭包
    js yarn
    js npm
    vue3 vite
    node 错误处理
    node fs
    linux包管理工具使用和区别(转)
    MySQL数据库学习----理论基础
  • 原文地址:https://www.cnblogs.com/chenzechao/p/14173043.html
Copyright © 2011-2022 走看看