Академический Документы
Профессиональный Документы
Культура Документы
= 9
Aim – To retrieve data from the tables of the database using order by
and group by commands.
Syntax
ORDER BY<sort specification> [{,<sort specification>}…]
<sort specification> - <key expression>[asc|desc][nulls first |nulls
last]
Example
SELECT name, price
From items
ORDER BY price asc;
Now we will apply this order by command on our database firstly we
apply this order by clause on the first table of our project that is the
account _master table in this we arrange our data in ascending order in
context to the balance attribute of the table.
Snapshot
Similarly we will use the command on the second table of the project
Which is the branch _master in this we have used order by clause on
the
Branch _city it will arrange the data in descending order
Group Aggregation Using Group By
Aggregate functions return a single piece of summary information
about an entire set of rows .what if we wanted the aggregates to all
groups in one query .SQL uses the GROUP BY clause to specify the
attributes that determine the grouping .
Example
SELECT storied, SUM (price)
FROM orders
GROUP BY storied;