使用显示标签

可以将显示标签指定给计算或派生的数据列,以替换缺省列头 expression。在图 1图 3图 1中,派生数据显示在 expression 列中。下列查询还显示派生值,但显示派生值的列具有描述性头 taxed

图: 查询

SELECT stock_num, description, unit_price, 
          unit_price * 1.07 taxed
          FROM stock
          WHERE unit_price >= 400;
结果显示将标记 taxed 指定给用于显示操作 unit_price * 1.07 的结果的投影列表中的表达式。

图: 查询结果

stock_num description     unit_price            taxed
          
          1 baseball gloves    $800.00          $856.00
          1 baseball gloves    $450.00          $481.50
          4 football           $960.00         $1027.20
          4 football           $480.00          $513.60
          7 basketball         $600.00          $642.00
          8 volleyball         $840.00          $898.80
          102 bicycle brakes     $480.00          $513.60
          111 10-spd, assmbld    $499.99          $534.99
          112 12-spd, assmbld    $549.00          $587.43
          113 18-spd, assmbld    $685.90          $733.91
          203 irons/wedge        $670.00          $716.90
在下列查询中,为显示操作 total_price + 6.50 的结果的列定义标签 surcharge

图: 查询

SELECT item_num, order_num, quantity,
            total_price, total_price + 6.50 surcharge
            FROM items
            WHERE quantity < 5; 
在输出中对 surcharge 列添加标签。

图: 查询结果

item_num   order_num quantity total_price    surcharge 
        
        1        1001        1     $250.00       $256.50 
        1        1002        1     $960.00       $966.50
        2        1002        1     $240.00       $246.50
        1        1003        1      $20.00        $26.50
        2        1003        1     $840.00       $846.50
        ⋮
        1        1023        2      $40.00        $46.50
        2        1023        2     $116.00       $122.50
        3        1023        1      $80.00        $86.50
        4        1023        1     $228.00       $234.50
        5        1023        1     $170.00       $176.50
        6        1023        1     $190.00       $196.50
下列查询将标签 span 指定给显示从 DATETIME 列 res_dtime 减去 DATETIME 列 call_dtime 的结果的列。

图: 查询

SELECT customer_num, call_code, call_dtime, 
          res_dtime - call_dtime span
          FROM cust_calls
          ORDER BY customer_num;
在输出中标记了 span 列。

图: 查询结果

customer_num call_code call_dtime               span
        
        106 D         1998-06-12 08:20         0 00:05 
        110 L         1998-07-07 10:24         0 00:06
        116 I         1997-11-28 13:34         0 03:13
        116 I         1997-12-21 11:24         5 20:55
        119 B         1998-07-01 15:00         0 17:21
        121 O         1998-07-10 14:05         0 00:01
        127 I         1998-07-31 14:30