Hello people,
as wrote in title I'm going crazy with a "complex" SQL select.
This is the seelct: This select works fine, and the output is like:
What I'm try to do now, is differentiate the HAVING count clause.
This mean I want "HAVING count(*) > X" based on T_IM_MNC table.
For example:
T_IM_MNC=01 => HAVING count(*) > 5
T_IM_MNC=02 => HAVING count(*) > 3
T_IM_MNC=03 => HAVING count(*) > 7
Is it possible in one query?
Could you please help me?
---------- Post updated at 04:54 AM ---------- Previous update was at 04:30 AM ----------
AHEM! After a cup of coffee I find myself the solution... It was so simple! That's why I'm going crazy!
Well, hope my post will help someone in the future! ^_^
I prefer case for situations like this, and generally -- you can hang nice comments. CASE can either key off logical predicates including expression IS NULL (CASE WHEN boolean_expression THEN result ....) or off values (CASE expression WHEN value THEN result ....). CASE is especailly grand for avoiding OR on indexed columns, which generally prevents using the index! It seems to be more portable and versatile than DECODE() and ISNULL():
You said
so the CASE WHEN logical form is:
and assuming these are the only T_IM_MNC values, use ELSE:
but since only one expression is being tested, we can use the even simpler if more restricted decode or CASE expression WHEN test_value form:
Hi All,
I had a query related to sql select replace command.
i have a table named clusters and it looks like this
Code:
name characteristics
sample 1.1 parent
sample 1.2 ... (2 Replies)
Hi All,
I had a query related to sql select update replace command.
i have a table named clusters and it looks like this
name model characteristics
sample1.1 +123 parent
sample1.2 -456 clone
sample1.3 +122 ... (5 Replies)
I know I know..
for sure one of the easier mysql statements. But somehow I can not figure out this.
I expect to see all distinct items of 'data_12' where 'kwroot' has 'straxx' in, and in the same row 'data_12' ist (not = 'kwsearched' in any existing row)
data_12 ... (6 Replies)
Hi there
I have a database on a remote box and i have been using shell script to insert data into it for example, i could have a script that did this
SN=123456
n=server1
m=x4140
sql="UPDATE main SET hostname='$n',model='$m' WHERE serial='$SN';"
echo $sql |/usr/sfw/bin/mysql -h... (4 Replies)
count.sh#!/bin/ksh
SQL1=`sqlplus -s usr/pwd @count.sql $1 $2 $3`
SQL2=`sqlplus -s usr/pwd @selectall.sql $1 $2 $3`
LIST="Count Select_All"
select i in $LIST
do
if
then
echo $SQL1
elif
then
echo $SQL2
fi
done (2 Replies)
Dear All ,
I have file1.txt contain values like the following:
----------
23
24
25
and I have shell script which has the following :
more file1.txt | awk '{print "select 'DUMP',CODE1||'|'||CODE2||'|'||CODE3 from CODE where CODE1='" $1 "';"}' > file2.sql
all I need is to have the... (6 Replies)
Hi,
I need to get the value from the table using the sql command and store this value into the unix variable so that i can use this value for furthure use..
Please can any body help me in this regards
Thanks & Regards
Abdul Hafeez Shaik (17 Replies)
I have following.
.
.
.
$userid = 2
.
$query = "select username from users where userid = ".$userid.";";
.
$username = $line;
$data="Some Data Here";
.
$query = "insert into logger (username, data) valuse ($username, $data);";
.
I would like to not have 2 database calls. (3 Replies)
Hi,
I have about 12 columns and 15 rows to be retrived from sybase isql command through unix. But when i output the sql into a file and see it, the formatting is going for a toss. can someone please suggest how can i get the result correctly in the output file ?
Thanks,
Sateesh (2 Replies)
Hello
I would like to perform a select from a oracle table and return those values to my shell script
For example:
site=head -1 $infile | cut -c1-15 | awk '{printf "s%", $0}
sqlplus -s /nolog |& #Open pipe to sql
select col1, col2, col3, col4
from oracle_table
where col5 =... (6 Replies)