Case Statements:
sql
Copy code
SELECT column1, column2,
CASE
WHEN condition1 THEN result1
WHEN condition2 THEN result2
ELSE result3
END AS alias
FROM table_name;
Subqueries:
sql
Copy code
SELECT column1
FROM table1
WHERE column2 IN (SELECT column3 FROM table2 WHERE condition);
Keys:
Primary Key:
sql
Copy code
CREATE TABLE table_name (
id INT PRIMARY KEY,
column1 datatype,
column2 datatype,
...
);
Foreign Key:
sql
Copy code
CREATE TABLE table_name (
id INT PRIMARY KEY,
foreign_id INT,
column1 datatype,
column2 datatype,
FOREIGN KEY (foreign_id) REFERENCES other_table(id)
);
Wildcards:
sql
Copy code
SELECT column1
FROM table_name
WHERE column2 LIKE 'abc%'; Case Statements:
sql
Copy code
SELECT column1, column2,
CASE
WHEN condition1 THEN result1
WHEN condition2 THEN result2
ELSE result3
END AS alias
FROM table_name;
Subqueries:
sql
Copy code
SELECT column1
FROM table1
WHERE column2 IN (SELECT column3 FROM table2 WHERE condition);
Keys:
Primary Key:
sql
Copy code
CREATE TABLE table_name (
id INT PRIMARY KEY,
column1 datatype,
column2 datatype,
...
);
Foreign Key:
sql
Copy code
CREATE TABLE table_name (
id INT PRIMARY KEY,
foreign_id INT,
column1 datatype,
column2 datatype,
FOREIGN KEY (foreign_id) REFERENCES other_table(id)
);
Wildcards:
sql
Copy code
SELECT column1
FROM table_name
WHERE column2 LIKE 'abc%'
Certainly! Here's an example of performing the ORDER BY clause on two columns in the EMPLOYEE table:
sql
Copy code
SELECT empId, name, dept, grade
FROM EMPLOYEE
ORDER BY grade DESC, name ASC;
In this example, the ORDER BY clause is applied to the grade column in descending order (DESC) first. Then, if there are multiple rows with the same grade, the name column is used to sort those rows in ascending order (ASC).
The result will be a sorted result set where the rows are arranged based on the grade in descending order. Within each grade, the rows will be further sorted based on the name in ascending order.
You can modify the column names and the sort order based on your specific requirements. Simply specify the desired columns in the ORDER BY clause and indicate whether you want them sorted in ascending (ASC) or descending (DESC) order.
select avg(grade) from EMPLOYEE
select avg(grade) from EMPLOYEE where dept='Accounting'
select * from EMPLOYEE where grade<(select avg(grade) from EMPLOYEE where dept='Accounting')
Certainly! Here's an example of performing the ORDER BY clause on two columns in the EMPLOYEE table:
sql
Copy code
SELECT empId, name, dept, grade
FROM EMPLOYEE
ORDER BY grade DESC, name ASC;
In this example, the ORDER BY clause is applied to the grade column in descending order (DESC) first. Then, if there are multiple rows with the same grade, the name column is used to sort those rows in ascending order (ASC).
The result will be a sorted result set where the rows are arranged based on the grade in descending order. Within each grade, the rows will be further sorted based on the name in ascending order.
You can modify the column names and the sort order based on your specific requirements. Simply specify the desired columns in the ORDER BY clause and indicate whether you want them sorted in ascending (ASC) or descending (DESC) order.
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}