菜单 学习猿地 - LMONKEY

VIP

开通学习猿地VIP

尊享10项VIP特权 持续新增

知识通关挑战

打卡带练!告别无效练习

接私单赚外块

VIP优先接,累计金额超百万

学习猿地私房课免费学

大厂实战课仅对VIP开放

你的一对一导师

每月可免费咨询大牛30次

领取更多软件工程师实用特权

入驻
35
0

常用sql

原创
05/13 14:22
阅读数 27621

1.查看数据库中有多少表

select count(*)  from user_tables;

2.查看数据库所有表的名字

select table_name from user_tables;

3.查看数据库表的创建时间和最后一次的修改时间

select object_name,created,last_ddl_time from user_objects;

4.查看导出的dmp文件的路径

select * from dba_directories;

5.oracle查看表中小于当前日期的上一个工作日

select max(d_date) from 表名 where  type=1 and to_date(d_date,'yyyyMMdd')<date'2020-11-25'

6.hive中执行大于时间点的数据

select * from where add_time>'2020-12-31 09:00:00'

命令行登录oracle 

sqlplus as sysdba

 

 

mysql 

列转行

    变为  

 

 

 sql语句

SELECT a.name,
    substring_index( substring_index(a.value,    ',',    b.help_topic_id + 1),',' ,- 1) AS shareholder
FROM
    test_counter a
JOIN mysql.help_topic b ON b.help_topic_id < (
    length(a.value) - length(REPLACE (a.value, ',', '')) + 1)

行转列

变为

 

 sql语句

SELECT name,GROUP_CONCAT(shareholder) as value from yyf_test GROUP BY name

扩展

变为

 

 

 sql语句

SELECT name,

 max(CASE subject WHEN'语文' THEN score ELSE 0 END) 语文,

 max(CASE subject WHEN'数学' THEN score ELSE 0 END) 数学,

 max(CASE subject WHEN'外语' THEN score ELSE 0 END) 外语

FROM test

GROUP BY name

 

发表评论

0/200
35 点赞
0 评论
收藏