Home » SQL & PL/SQL » SQL & PL/SQL » What wroung i am doing In this query Please suggest
What wroung i am doing In this query Please suggest [message #600694] Mon, 11 November 2013 05:36 Go to next message
sahnra
Messages: 39
Registered: November 2013
Location: India
Member
Select t1.company, t4.proc_group,
(

select rtrim(t4.first_name)||''||t4.last_name from lawson.zquser t4 where t4.company = t1.company and t4.ZQ_User_ID=t1.service_mgr and t4.position_code= 'BTM')btm,

(
select rtrim(t5.first_name)||''||t5.last_name from lawson.zquser t5 where t5.company = t1.company and t1.hrp = t5.zq_user_id and t5.position_code = 'CSP') csp,

Count (t2.employee)countofemployees,


sum(t3.gross_pay)total_gross_pay
from lawson.comprof t1, lawson.employee t2, lawson.paymastr t3, Lawson.prprocgrp t4

where
t1.company = t2.company and t1.company= t3.company
and t1.process_level= t2.process_level and t1.process_level = t3.process_level and t1.process_level=t4.process_level
and t2.employee=t3.employee
AND
CASE

WHEN (
t3.check_date>=sysdate-15
and t1.pay_frequency = 3 ) then
'6000'

WHEN
(
t1.pay_frequency = 2
and t3.check_date>=sysdate-7
)
then '4000'


end "Gross_pAY"
and t1.comp_status= 'A'
having (sum(t3.gross_pay)>=0 and sum (t3.gross_pay)<=6000))
group by t1.company, t4.proc_group,t1.service_mgr,t1.hrp

order by t1.company, t4.proc_group
Re: What wroung i am doing In this query Please suggest [message #600696 is a reply to message #600694] Mon, 11 November 2013 05:49 Go to previous messageGo to next message
Littlefoot
Messages: 21808
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Who could tell? You posted a query and said that there's something wrong.

We don't have your tables nor data. We don't know what is this query supposed to return, and why is the result set it returns "wrong". Does it return anything at all, or is there any error? If so, which one is it?
Re: What wroung i am doing In this query Please suggest [message #600700 is a reply to message #600696] Mon, 11 November 2013 06:08 Go to previous messageGo to next message
sahnra
Messages: 39
Registered: November 2013
Location: India
Member
Showing error (ORA-00920: invalid relational operator)
on (end "Gross_pAY")
Re: What wroung i am doing In this query Please suggest [message #600702 is a reply to message #600700] Mon, 11 November 2013 06:23 Go to previous messageGo to next message
Littlefoot
Messages: 21808
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
This is your query, formatted. Two lines are commented: one is "Gross_pAY" label (which should not be used here); another one is superfluous closing bracket. Try to run it again and see what happens.
  SELECT t1.company,
         t4.proc_group,
         (SELECT RTRIM (t4.first_name) || '' || t4.last_name
            FROM lawson.zquser t4
           WHERE     t4.company = t1.company
                 AND t4.ZQ_User_ID = t1.service_mgr
                 AND t4.position_code = 'BTM')
            btm,
         (SELECT RTRIM (t5.first_name) || '' || t5.last_name
            FROM lawson.zquser t5
           WHERE     t5.company = t1.company
                 AND t1.hrp = t5.zq_user_id
                 AND t5.position_code = 'CSP')
            csp,
         COUNT (t2.employee) countofemployees,
         SUM (t3.gross_pay) total_gross_pay
    FROM lawson.comprof t1,
         lawson.employee t2,
         lawson.paymastr t3,
         Lawson.prprocgrp t4
   WHERE     t1.company = t2.company
         AND t1.company = t3.company
         AND t1.process_level = t2.process_level
         AND t1.process_level = t3.process_level
         AND t1.process_level = t4.process_level
         AND t2.employee = t3.employee
         AND CASE
                WHEN (t3.check_date >= SYSDATE - 15 AND t1.pay_frequency = 3)
                THEN
                   '6000'
                WHEN (t1.pay_frequency = 2 AND t3.check_date >= SYSDATE - 7)
                THEN
                   '4000'
             END
-- "Gross_pAY"                           --> commented!
         AND t1.comp_status = 'A'
  HAVING (SUM (t3.gross_pay) >= 0 AND SUM (t3.gross_pay) <= 6000)
--)                                      --> commented!
GROUP BY t1.company,
         t4.proc_group,
         t1.service_mgr,
         t1.hrp
ORDER BY t1.company, t4.proc_group
Re: What wroung i am doing In this query Please suggest [message #600704 is a reply to message #600694] Mon, 11 November 2013 06:28 Go to previous messageGo to next message
Solomon Yakobson
Messages: 3273
Registered: January 2010
Location: Connecticut, USA
Senior Member
Look at

         AND CASE
                WHEN (t3.check_date >= SYSDATE - 15 AND t1.pay_frequency = 3)
                THEN
                   '6000'
                WHEN (t1.pay_frequency = 2 AND t3.check_date >= SYSDATE - 7)
                THEN
                   '4000'
             END


Do you see a condition there? All it does is calculates CASE expression value.

SY.
Re: What wroung i am doing In this query Please suggest [message #600707 is a reply to message #600704] Mon, 11 November 2013 07:00 Go to previous messageGo to next message
sahnra
Messages: 39
Registered: November 2013
Location: India
Member
Value 4000 and 6000 are also to be stored into a new column how we can do that..?

AND CASE
WHEN (t3.check_date >= SYSDATE - 15 AND t1.pay_frequency = 3)
THEN
'6000'
WHEN (t1.pay_frequency = 2 AND t3.check_date >= SYSDATE - 7)
THEN
'4000'
END


Re: What wroung i am doing In this query Please suggest [message #600708 is a reply to message #600707] Mon, 11 November 2013 07:11 Go to previous messageGo to next message
Solomon Yakobson
Messages: 3273
Registered: January 2010
Location: Connecticut, USA
Senior Member
Again, your condition is:

AND x


which makes no sense. And I have no clue what you mean by "Value 4000 and 6000 are also to be stored into a new column how we can do that.." You have WHERE clause condition. What it has to do whit storing new column? Anyway, based on your "Can we club" post, I'd guess you want:

         AND t3.gross_pay <= CASE
                               WHEN (t3.check_date >= SYSDATE - 15 AND t1.pay_frequency = 3)
                                 THEN
                                   '6000'
                               WHEN (t1.pay_frequency = 2 AND t3.check_date >= SYSDATE - 7)
                                 THEN
                                   '4000'
                             END


If not, you need to explain in wirds what thi condition is supposed to check.

SY.
Re: What wroung i am doing In this query Please suggest [message #600710 is a reply to message #600708] Mon, 11 November 2013 07:36 Go to previous messageGo to next message
sahnra
Messages: 39
Registered: November 2013
Location: India
Member
There are Two condition
1 st one is where Peroid End date of employee is System -7 and t1.pay_frequency = 2 and having (sum(t3.gross_pay)>=0 and sum (t3.gross_pay)<=4000)and employee gross_pay is between red criteria

2nd. System -15 and t1.pay_frequency = 3 and having (sum(t3.gross_pay)>=0 and sum (t3.gross_pay)<=6000)


suppose 1st condition is true then new colunm is created and showing 4000 condition is true.
Re: What wroung i am doing In this query Please suggest [message #600712 is a reply to message #600710] Mon, 11 November 2013 07:45 Go to previous messageGo to next message
sahnra
Messages: 39
Registered: November 2013
Location: India
Member
For example red one is new column


Gross Pay

3000

fall under
4000

[Updated on: Mon, 11 November 2013 07:48]

Report message to a moderator

Re: What wroung i am doing In this query Please suggest [message #600715 is a reply to message #600712] Mon, 11 November 2013 08:09 Go to previous messageGo to next message
sahnra
Messages: 39
Registered: November 2013
Location: India
Member
Query is working fine only Please Let Me know can we store 4000 and 3000 into new column if we can then how..?
note:-4000 and 3000 value are not from any table
AND t3.gross_pay <= CASE
WHEN (t3.check_date >= SYSDATE - 15 AND t1.pay_frequency = 3)
THEN
'6000' WHEN (t1.pay_frequency = 2 AND t3.check_date >= SYSDATE - 7)
THEN
'4000' END


Re: What wroung i am doing In this query Please suggest [message #600746 is a reply to message #600715] Tue, 12 November 2013 00:36 Go to previous message
sahnra
Messages: 39
Registered: November 2013
Location: India
Member
Thanks all for your help query is working fine
Previous Topic: does a query can use more than one index on table at a time
Next Topic: Can We Club both Query....? Please Help ..
Goto Forum:
  


Current Time: Thu Apr 25 04:09:50 CDT 2024