返回顶部

收藏

mysql别名使用

更多
mysql>
mysql> CREATE TABLE driver_log
    -> (
    ->  rec_id          INT UNSIGNED NOT NULL AUTO_INCREMENT,
    ->  name            VARCHAR(20) NOT NULL,
    ->  trav_date       DATE NOT NULL,
    ->  miles           INT NOT NULL,
    ->  PRIMARY KEY (rec_id)
    -> );
Query OK, 0 rows affected (0.01 sec)

mysql>
mysql> INSERT INTO driver_log (name,trav_date,miles)
    ->  VALUES
    ->          ('Ben','2010-11-30',152),
    ->          ('Suzi','2010-11-29',391),
    ->          ('Henry','2010-11-29',300),
    ->          ('Henry','2010-11-27',96),
    ->          ('Ben','2010-11-29',131),
    ->          ('Henry','2010-11-26',115),
    ->          ('Suzi','2010-12-02',502),
    ->          ('Henry','2010-12-01',197),
    ->          ('Ben','2010-12-02',79),
    ->          ('Henry','2010-11-30',203)
    -> ;
Query OK, 10 rows affected (0.00 sec)
Records: 10  Duplicates: 0  Warnings: 0

mysql>
mysql> SELECT name, trav_date, miles AS distance FROM driver_log
    -> ORDER BY distance;
+-------+------------+----------+
| name  | trav_date  | distance |
+-------+------------+----------+
| Ben   | 2010-12-02 |       79 |
| Henry | 2010-11-27 |       96 |
| Henry | 2010-11-26 |      115 |
| Ben   | 2010-11-29 |      131 |
| Ben   | 2010-11-30 |      152 |
| Henry | 2010-12-01 |      197 |
| Henry | 2010-11-30 |      203 |
| Henry | 2010-11-29 |      300 |
| Suzi  | 2010-11-29 |      391 |
| Suzi  | 2010-12-02 |      502 |
+-------+------------+----------+
10 rows in set (0.00 sec)

mysql>
mysql> drop table driver_log;
Query OK, 0 rows affected (0.00 sec)

标签:SQL,MySQL

收藏

0人收藏

支持

0

反对

0

发表评论