Download IBM Informix Guide to SQL: Tutorial, Version 5.2

Transcript
Single-Table SELECT Statements
The span column is labeled in the output.
customer_num user_id
116
116
106
121
127
110
119
mannyn
mannyn
maryj
maryj
maryj
richc
richc
call_code call_dtime
I
I
D
O
I
L
B
1990-12-21
1990-11-28
1991-06-12
1991-07-10
1991-07-31
1991-07-07
1991-07-01
span
11:24
13:34
08:20
14:05
14:30
10:24
15:00
5
0
0
0
20:55
03:13
00:05
00:01
0 00:06
0 17:21
Sorting on Derived Columns
When you want to ORDER BY an expression, you can use either the display
label assigned to the expression or an integer.
SELECT customer_num, user_id, call_code,
call_dtime, res_dtime - call_dtime span
FROM cust_calls
ORDER BY span
This query retrieves the same data from the cust_calls table as the previous
query, but here the ORDER BY clause causes the data to be displayed in
ascending order of the derived values in the span column.
customer_num user_id
127
121
106
110
116
119
116
maryj
maryj
maryj
richc
mannyn
richc
mannyn
call_code call_dtime
I
O
D
L
I
B
I
1991-07-31
1991-07-10
1991-06-12
1991-07-07
1990-11-28
1991-07-01
1990-12-21
span
14:30
14:05
08:20
10:24
13:34
15:00
11:24
0
0
0
0
0
5
00:01
00:05
00:06
03:13
17:21
20:55
The next version uses an integer to represent the result of the operation
res_dtime - call_dtime and retrieves the same rows.
SELECT customer_num, user_id, call_code,
call_dtime, res_dtime - call_dtime span
FROM cust_calls
ORDER BY 5
2-46
Simple SELECT Statements