Have been writing the shell script such as :
#! /bin/bash
`sqlplus -s <username>/<passwd>@dbname`
set echo on
set pagesize 0
set verify off
set lines 32000
set trimspool on
set feedback off
`SELECT tr.number, count(*) as total
FROM <dbname>.<tablename1> tr
LEFT JOIN <tablename2> t2 ON t2.id2 = tr.id1
LEFT JOIN <tablename3> t3 ON t3.id2 = tr.id1
LEFT JOIN <tablename4> t4 ON t4.id2 = tr.id1
WHERE tr.TIMESTAMP > SYSDATE - 75 / 1440
AND tr.TIMESTAMP <= SYSDATE - 15 / 1440
and (t2.number like '2____' OR t2.number like '3____' OR t2.number like '99____' )
AND tr.id = 703 and t2.v1 = 100
group by (tr.number);`
exit;
EOF
Currently my output is like ::
tr.number count(*)
27684 76
27050 9
37744 7
997717 11
997797 8
37224 3
I want to group the count of numbers 2_, 3__, 99__ such as
tr.number count(*)
2____ 76+9
3____ 7+3
99_____ 11+8
the output should be ONLY in 3 rows with starting digits as 2,3 and 99 in three rows as shown above.
_
represents 4 places.
Please advise.
P.S. Could you please advise why is it essential to put SET operators and their brief description.
Thanks !