全量查询数据库 表名 字段名 字段类型 等杂SQL 完了整理

select * from information_schema.columns   where table_name='user_award_experience';

select column_name,DATA_TYPE,COLUMN_TYPE,IS_NULLABLE,COLUMN_COMMENT from information_schema.columns where COLUMN_TYPE='VARCHAR' and 


(SELECT TABLE_SCHEMA,TABLE_NAME,COLUMN_NAME,DATA_TYPE,COLUMN_COMMENT from information_schema.columns WHERE TABLE_SCHEMA='krplus2' and DATA_TYPE='varchar' and CHARACTER_MAXIMUM_LENGTH >=8);

SELECT TABLE_SCHEMA,CONCAT(COLUMN_NAME,'.',DATA_TYPE),TABLE_NAME,COLUMN_NAME,DATA_TYPE,COLUMN_COMMENT from information_schema.columns WHERE TABLE_SCHEMA='krplus2' and DATA_TYPE='varchar' and CHARACTER_MAXIMUM_LENGTH >=8   ORDER BY  TABLE_NAME;


SELECT TABLE_NAME AS  c  from information_schema.columns WHERE TABLE_SCHEMA='krplus2' and DATA_TYPE='varchar' and CHARACTER_MAXIMUM_LENGTH >=8 GROUP BY  TABLE_NAME;

SELECT  a.*  from (SELECT TABLE_NAME from information_schema.columns WHERE TABLE_SCHEMA='krplus2' and DATA_TYPE='varchar' and CHARACTER_MAXIMUM_LENGTH >=8) a ;

查询某库某些表有某某字段

SELECT DISTINCT
t.table_name,
c.COLUMN_NAME
FROM
information_schema.TABLES t
INNER JOIN information_schema.COLUMNS c
ON c.TABLE_NAME = t.TABLE_NAME
where t.TABLE_TYPE = 'base table'
and c.COLUMN_NAME = 'uid'
and t.TABLE_SCHEMA = 'krplus2'
ORDER BY t.TABLE_TYPE

数据库位运算

select uid from user_type where (((industry_investor_enterpriser >> 9) & 0x01 = 1)
or ((industry_investor_enterpriser >> 27) & 0x01 = 1)) and uid = '618168445';

SELECT u.id,u.phone,ut.industry_investor_enterpriser FROM user_type ut
INNER JOIN `user` u ON u.id=ut.uid WHERE ut.auth_enterpriser =1 AND u.phone <>''
AND (ut.industry_investor_enterpriser&134217728=134217728 OR ut.industry_investor_enterpriser&67108864=67108864)

时间:
SELECT DISTINCT(mark.uid)  from market_daily_life mark INNER JOIN (select uid from user_type where uid not in(1)   and  ( ( ( industry_investor_enterpriser >> 7 ) & 0x01 = 1 ) OR ( ( industry_investor_enterpriser >> 8 ) & 0x01 = 1 ) OR ( ( industry_investor_enterpriser >> 11 ) & 0x01 = 1 ) ) ) users on mark.uid=users.uid  and mark.create_time  BETWEEN (SELECT DATE_ADD(now(),INTERVAL -6 MONTH)) and now();

快   如去掉 and ustype.uid >11111 order by ustype.uid asc limit  5 下面的快           这是为何

select ustype.uid from user_type  ustype where ustype.uid not in(1)   and  ( ( ( ustype.industry_investor_enterpriser >> 7 ) & 0x01 = 1 ) OR ( ( ustype.industry_investor_enterpriser >> 8 ) & 0x01 = 1 ) OR ( ( ustype.industry_investor_enterpriser >> 11 ) & 0x01 = 1 ) ) and EXISTS (SELECT DISTINCT
(uid) from market_daily_life  mark WHERE   mark.uid=ustype.uid)  and ustype.uid >11111 order by ustype.uid asc limit  5;

 SELECT DISTINCT(mark.uid)  from market_daily_life mark INNER JOIN (select uid from user_type where uid not in(1)   and  ( ( ( industry_investor_enterpriser >> 7 ) & 0x01 = 1 ) OR ( ( industry_investor_enterpriser >> 8 ) & 0x01 = 1 ) OR ( ( industry_investor_enterpriser >> 11 ) & 0x01 = 1 ) ) ) users on mark.uid=users.uid  and mark.uid >11111 order by mark.uid asc limit  5;

 

 

查询数据中字段最长值

SELECT
    `title`,
    length(`title`)
FROM
    technology_achievement_tranfrom
WHERE
    length(`title`) = (
        SELECT
            max(length(`title`))
        FROM
            technology_achievement_tranfrom
    )

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值