SQL (||, DISTINCT) & PHP (switch)

Hyun Seo (Lucy) Lee 이현서·2020년 9월 19일
0
post-thumbnail

2020년 9월 17일

스마트/하이브리드 앱/웹 개발

복습 Entry no.4

SQL

Concatenation Operator

> SELECT 컬럼||'리터럴'||... FROM 테이블;
--> in here, '리터럴' (literal) means a character, number or date that is included in the SELECT statement.

Ex: SELECT ename||sal 이름급여 FROM emp; --> spits back name and sal like 안영희4800 ... under the header 이름급여.

  • 근데 홍길동4830은 너무 다닥다닥 붙어있으니까, so let's add space in between using a literal:

> SELECT ename||' '||sal 이름_급여 FROM emp;

--> then now this will display:

이름_급여


안영희 4800

> SELECT ename||'의 업무는 '||job||'입니다.' FROM emp;

      ENAME||'의 업무는 '||job||'입니다.'                    <-- If you don't specify a nickname, this is gonna happen lol

      - - - - - - - - - - - - - -  - - - - - - - - - - - - - - - - - -

       안영희의 업무는 경영입니다.                               (<-- side note, 경영 means administration)

        .

        .

        .

And if you ever want to put mathematical expression(s) within a query that invovles concatenation operators, make sure you put parentheses around the math expression. (ex: SELECT ename||' '||(sal+100) FROM emp;)

DISTINCT, ALL Keywords ( for ALL, it's the same as default, just gives you all the entries)

 > SELECT DISTINCT job 업무 FROM emp;

   업무

   - - - - - - - - - -  -- - 

   회계

   개발

   지원

   .

   .

   .

PHP

(side note: in linux cmd, > whoami --> tells you who you are, aka your ID (ex: te, or st01))

(side note #2: > vi 2-1.php --> opens up the file. you can also edit it. Unix also uses vi)

(side note #3: > ls --> tells you what's in the folder (kind of like Windows cmd's dir command))

Note: the connection between 2-1.html and 2-1.php is also a hyperlink. Not only <a> tags are hyperlinks.

Predefined Variables: $_POST, $_GET

(note: in $_POST["a"], never forget the double quotes)

round() function --> 반올림 함수. 0.5를 넣으면 1이 되고 0.4를 넣으면 0이 되는. SQL also has it
(but also note: in reality companies never round their employees' salaries, they usually truncate it using the trunc() function lol... there's also a 10원 이하는 안줘도 되는 룰.)

Switch

  • 얘는 condition에 따른거 아님. 다른말고 조건문이 아님. 완전히 분기문 (branch statement) 임

  • switch has a much higher 가독성 (readability) than if-statements. (just like how for-looks have much higher readability than while-loops). It's also more efficient because it's mutually exclusive, meaning it will only execute one case, not all cases.

  switch (변수 또는 수식) {

        case 값:

                         ...

                        break;

        case 값:

                         ...

                        break;

          default:

                          ...

   }

ex:

 switch ($a) {

       case 'female':

           .....

           break;

        ....

        default :       <-- place this only if you want the program to do something when none of the cases match. 

       ....             also, remember that default section doesn't need a break command at the end!

 }

(side note: For web developers, JavaScript is so important. Almost every web developer owns a book on JavaScript at home.)

(side note 2: Java vs JavaScript --> In Java, you make your own classes. In JavaScript, you use classes that are provided by JS.)

(side note 3: JavaScript has a LOT of functions! their classes and their methods are innumerable and useful, especially for web)

PHP and ASP.NET can't take in user keyboard & mouse inputs, so can't make games with them.

그치만 PHP가 database 랑 연동하기가 제일 쉬움. so it's used as server-side language a lot.

For programming, there are most likely going to be 3 main markets in the future:

  1. app 2. apple apps 3. web apps. 서버 programming

(side note: Google은 다 서버에서 작업함. 그래서 data center가 여의도 만함...ㅋㅋㅋ 전기 엄청 많이씀. 그래서 발전소도 아예 따로 지음.
by IBM themselves. IBM is the one who created the SQL language. They have expertise in databases, hard drive, and memory)

  • ceil() function --> rounds a number to the nearest greater integer. Basically can be called a roundup function. (ex: ceil(4.3) --> 5

    ex2: ceil(-3.14) --> -3)

0개의 댓글