SQL
Certificates
- Introduction to SQL https://www.datacamp.com/statement-of-accomplishment/course/02d7e2545a8b1ab0922067ed9271f2dc90211a94?raw=1 https://www.codecademy.com/profiles/Khanh.Le/certificates/042a4e5884e3eb6ea1f2a12be6abb851
- Intermediate SQL https://www.datacamp.com/statement-of-accomplishment/course/4490b59dc6b22b8bf18d34ef0c115ffa62b68689?raw=1
- Joining Data in SQL https://www.datacamp.com/statement-of-accomplishment/course/4fc917b3bcd186c1e65339398fe23adf639f016b?raw=1
- Improving query performance in PostgreSQL https://www.datacamp.com/statement-of-accomplishment/course/a445e2e4ac33be172d3fbcdc698c624d3e241ac4?raw=1
Learn SQL Course
Best Practices
- LIKE ANY(ARRAY('%a', '%b'))
- OR -> IN (1,3), number better than text
- WITH clause for creating function, temp table (common table expression)
- Partition column in WHERE
- SELECT * FROM pg_indexes
- CREATE INDEX CONCURRENTLY index_a ON tbl_b(col_c); create index for cols in WHERE
- https://www.sqlstyle.guide/
- q'[Content single quote ' do not need to double.]'
- LEFT JOIN (1:1 vs 1:n)
- MERGE INTO vs INSERT/UPDATE (condition duplicate table join)
- check index usaged, check no_result_cache, opt adaptive plans when use sql explain
- Based on statistics, Use index (1%) vs read whole table (25%)
EXEC dbms_stats.gather_system_stats('Start');
SELECT * FROM sys.aux_stats$;
ANALYZE TABLE <tbl> COMPUTE STATISTICS;
EXEC dbms_stats.gather_database_stats;
EXEC dbms_stats.gather_dictionary_stats;
EXEC dbms_stats.gather_schema_stats(ownname=>'SH');
EXEC dbms_stats.gather_table_stats(ownname=>'SH', tabname=>'tbl', cascade=>true);
SELECT * FROM dba_table_statistics WHERE table_name ='tbl';
- Explain plan
EXPLAIN PLAN FOR <sql>;
SELECT * FROM plan_table;
SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY());
EXPLAIN PLAN SET statement_id='myID' INTO my_tbl FOR <sql>;
- Cost (%CPU)
- IN (1,2,3,4) => BETWEEN 1 AND 4
- reused TYPE -> declare var1 table2.column3%TYPE;
- Convert OR(prevent index usages) to UNION ALL + AND for using INDEX
- nested sub query to join query
-
SELECT mum_distinct FROM dba_tab_columns WHERE table_name='tbl_name'
- less record table first, then more record table later
- CREATE INDEX for GROUP BY columns
- USE Minimum call to SYSDATE, NOT CURRENT_DATE
- condition JOIN, NOT IN, NOT EXISTS
- check tables with same alias
- inner join then left join
- where move to first inner join
- where in
- ROWNUM starts from 1; put it in the most outer clause
- materialzed view, auto refresh on commit; create index on view
- table partitioning
Paths
https://www.codecademy.com/paths/analyze-data-with-sql/tracks/analyze-data-sql-get-started-with-sql/modules/what-is-sql/lessons/why-sql-ii/exercises/sql-queries
Courses
- https://www.khanacademy.org/computing/computer-programming/sql
- https://www.tutorialspoint.com/sql/index.htm
- https://www.codecademy.com/learn/learn-sql
- https://www.guru99.com/sql.html
- https://www.codecademy.com/catalog/language/python
- https://www.w3schools.com/sql/default.asp
- Oracle SQL Performance Tuning Masterclass 2021
https://www.codecademy.com/learn/learn-sql
https://learn.datacamp.com/career-tracks/data-analyst-with-sql-server?version=1
https://www.codecademy.com/learn/sql-table-transformation
https://www.codecademy.com/learn/sql-analyzing-business-metrics
SQL Server Metadata Succinctly