Expresii

postat acum 4 ani de Stefanescu Mihai in categorie SQL

O expresie este o combinatie de valori, operatori si funtii SQL ce returneaza o valoare.

Expresiile SQL sunt similare formulelor si sunt folosite pentru a returna anumite date dintr-o baza de date.SintaxaMai jos am scris o interograde SELECT:

SELECT coloana1, coloana2, coloanaN 
FROM numele_tabelului 
WHERE [Contitie|Expresie];

Expresie Booleana

Acest tip de expresie returneaza datele ce se potrivesc unei anumite valori.

Pentru acest exemplu presupunem ca avem urmatorul tabel de angajati:

SQL> SELECT * FROM angajati;
+----+----------+--------+-----------+-----------+
| ID | NUME     | VARSTA | ADRESA    | SALARIU   |
+----+----------+--------+-----------+-----------+
|  1 | Ramesh   |    32  | Ahmedabad |  2000.00  |
|  2 | Khilan   |    25  | Delhi     |  1500.00  |
|  3 | kaushik  |    23  | Kota      |  2000.00  |
|  4 | Chaitali |    25  | Mumbai    |  6500.00  |
|  5 | Hardik   |    27  | Bhopal    |  8500.00  |
|  6 | Komal    |    22  | MP        |  4500.00  |
|  7 | Muffy    |    24  | Indore    | 10000.00  |
+----+----------+--------+-----------+-----------+

Iata si un exemplu de interogare ce na va returna randul ce se potriveste unui singure conditii:

SQL> SELECT * FROM angajati WHERE salariu = 10000;
+----+----------+--------+-----------+-----------+
| ID | NUME     | VARSTA | ADRESA    | SALARIU   |
+----+----------+--------+-----------+-----------+
|  7 | Muffy    |    24  | Indore    | 10000.00  |
+----+----------+--------+-----------+-----------+

Expresie numerica

Acest tip de expresie poate fi folosita la rezolvarea unei operatii matematice in orice interogare.

SQL> SELECT (7 + 9) AS Adunare
+----------+
| Adunare  |
+----------+
|       16 |
+----------+

Pentru acest tip de expresii exista o intraga serie de functii predefinite precum avg(), sum(), count(), s.a.m.d.

SQL> SELECT COUNT(*) AS "Numar Angajati" FROM angajati; 
+----------------+
| Numar Angajati |
+----------------+
|              7 |
+----------------+

Data Curenta

Acest tip de expresii returneaza data curenta setata in sistemul pe care ruleaza serverul.

SQL>  SELECT CURRENT_TIMESTAMP;
+---------------------+
| Current_Timestamp   |
+---------------------+
| 2015-26-03 10:43:27 |
+---------------------+

Iata inca un mod de a afisa data curenta:

SQL>  SELECT  GETDATE();
+---------------------+
| Current_Timestamp   |
+---------------------+
| 2015-26-03 10:43:27 |
+---------------------+

 

Sunt un tanar programator din Bucuresti ce lucreaza in PHP/Mysql (MySqli/PDO), Laravel, CodeIgniter, MySQL, PostgreSQL, Wordpress, HTML5/CSS3, Sass, Photoshop si multe altele.
Google+ Community Facebook Group
Acest articol a fost mutat de pe vechea platforma.
Pentru orice eroare aparuta la mutare va rog sa ma contactati!

Comentariu postate de download minecraft for free la data de 14.05.2019
I don't even know how I ended up here, but I thought this post was good. I do not know who you are but certainly you're going to a famous blogger if you aren't already ;) Cheers!
Comentariu postate de minecraft download pc la data de 15.05.2019
Hello, just wanted to tell you, I enjoyed this article. It was helpful. Keep on posting!
Comentariu postate de download minecraft pc la data de 16.05.2019
You're so awesome! I do not think I've truly read a single thing like that before. So nice to find another person with unique thoughts on this topic. Seriously.. thank you for starting this up. This web site is one thing that is needed on the web, someone with some originality!
Comentariu postate de minecraft download free pc la data de 17.05.2019
Hello i am kavin, its my first occasion to commenting anyplace, when i read this piece of writing i thought i could also make comment due to this sensible article.
Comentariu postate de how to download minecraft free la data de 17.05.2019
Great blog here! Additionally your site loads up fast! What web host are you the use of? Can I get your affiliate hyperlink in your host? I wish my web site loaded up as fast as yours lol