Vyhněte se běžným chybám

Aplikace SQL na reálné problémy

Dmitriy (Dima) Gorenshteyn

Lead Data Scientist, Memorial Sloan Kettering Cancer Center

Nezneužívejte komentáře

/* When selecting category and length
from films we need to use f, after this
I had a sandwich, it was a 
good sandwich ...*/
SELECT category, length
-- FROM actor as a
FROM film AS f
/* Inner join the table category 
with the film table */
INNER JOIN category AS c
ON f.film_id = c.film_id;

Nepište

  • Esej do komentářů.
Aplikace SQL na reálné problémy

Nezneužívejte komentáře





SELECT category, length
-- FROM actor as a
FROM film AS f
/* Inner join the table category 
with the film table */
INNER JOIN category AS c
ON f.film_id = c.film_id;

Nepište

  • Esej do komentářů.
  • Staré komentáře v dokončeném kódu.
Aplikace SQL na reálné problémy

Nezneužívejte komentáře





SELECT category, length

FROM film AS f
/* Inner join the table category 
with the film table */
INNER JOIN category AS c
ON f.film_id = c.film_id;

Nepište

  • Esej do komentářů.
  • Staré komentáře v dokončeném kódu.
  • Komentáře, které pouze opakují kód.
Aplikace SQL na reálné problémy

Nezneužívejte komentáře

/* When selecting category and length
from films we need to use f, after this
I had a sandwich, it was a 
good sandwich ...*/
SELECT category, length
-- FROM actor as a
FROM film AS f
/* Inner join the table category 
with the film table */
INNER JOIN category AS c
ON f.film_id = c.film_id;
SELECT category, length
FROM film AS f
INNER JOIN category AS c
ON f.film_id = c.film_id;
Aplikace SQL na reálné problémy

Nepoužívejte SELECT *

SELECT *
FROM film AS f
INNER JOIN category AS c
ON f.film_id = c.film_id;
release_year language_id rental_duration rental_rate length  .......
2009            1            4              6.99        173  .......    
2006            1            7              6.99        185  .......    
2004            1            5              4.99        153  .......    
2007            1            7              2.99        69   .......
Aplikace SQL na reálné problémy

Nepoužívejte SQL na programování

DO $$
BEGIN
   FOR counter IN 1..5 LOOP
     IF (counter = 2) THEN
      RAISE NOTICE 'BINGO!';
     ELSE 
      RAISE NOTICE 'Not BINGO :-(';
     END IF;
   END LOOP;
END; $$
NOTICE:  1 Not BINGO :-(
NOTICE:  1 BINGO!
NOTICE:  3 Not BINGO :-(
NOTICE:  4 Not BINGO :-(
NOTICE:  5 Not BINGO :-(
Aplikace SQL na reálné problémy

Pojďme si procvičit!

Aplikace SQL na reálné problémy

Preparing Video For Download...