Home » SQL & PL/SQL » SQL & PL/SQL » why this code with error?
why this code with error? [message #620020] Sun, 27 July 2014 22:54 Go to next message
hahaie
Messages: 194
Registered: May 2014
Senior Member
WITH QRY_BASE AS
(
    SELECT 'P1'PRODUCT,'T1'TYPE_PROD,120 WEIGHT FROM DUAL
    UNION 
    SELECT 'P2'PRODUCT,'T2'TYPE_PROD,120 WEIGHT FROM DUAL
    UNION 
    SELECT 'P3'PRODUCT,'T2'TYPE_PROD,120 WEIGHT FROM DUAL
    UNION 
    SELECT 'P4'PRODUCT,'T1'TYPE_PROD,120 WEIGHT FROM DUAL
    UNION 
    SELECT 'P5'PRODUCT,'T2'TYPE_PROD,120 WEIGHT FROM DUAL
    UNION 
    SELECT 'P6'PRODUCT,'T2'TYPE_PROD,120 WEIGHT FROM DUAL
    UNION 
    SELECT 'P7'PRODUCT,'T2'TYPE_PROD,120 WEIGHT FROM DUAL
    UNION 
    SELECT 'P8'PRODUCT,'T1'TYPE_PROD,120 WEIGHT FROM DUAL
    UNION 
    SELECT 'P9'PRODUCT,'T2'TYPE_PROD,120 WEIGHT FROM DUAL
    UNION 
    SELECT 'P10'PRODUCT,'T2'TYPE_PROD,120 WEIGHT FROM DUAL
)
SELECT SUM(WEIGHT),
       SUM(WEIGHT)/(SELECT SUM(Q.WEIGHT) FROM QRY_BASE Q)*100 PERCENT_WEI
FROM QRY_BASE B WHERE B.TYPE_PROD='T1'
Re: why this code with error? [message #620024 is a reply to message #620020] Sun, 27 July 2014 23:57 Go to previous messageGo to next message
hahaie
Messages: 194
Registered: May 2014
Senior Member
use
group by B.TYPE_PROD
after where statment to The error resolved!!!
Re: why this code with error? [message #620032 is a reply to message #620024] Mon, 28 July 2014 02:17 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
hahaie wrote on Mon, 28 July 2014 10:27
use
group by B.TYPE_PROD
after where statment to The error resolved!!!


Any why only group for TYPE_PROD? Why not group it with PRODUCT or WEIGHT? Or both? Or all of them?

How would anybody know what problem you are trying to solve unless you tell us the requirement.
Re: why this code with error? [message #620034 is a reply to message #620032] Mon, 28 July 2014 02:39 Go to previous message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

You know, if he is happy with what he found, what should we care? /forum/fa/3390/0/

Previous Topic: find different or missing rows in one table
Next Topic: Update a single character within string column
Goto Forum:
  


Current Time: Thu Apr 25 23:34:11 CDT 2024