全量查询数据库 表名 字段名 字段类型 等杂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;

你可能感兴趣的:(收集工具,sql,数据库整体)