Select the columns not in the group by clause
HelloMy version of DB is 10.0.2
I have query, where in I need to select two columns more but that should not be part of the group by Clause.
Does perform a work around?
SELECT F.custnum,
V.Import_date,
-- F.ErledigtMM,F.ErledigtGrundMM, (Columns to be selected additionally)
nvl(sum(nvl(round(V.VerAuf16/1000,2), 0) +nvl(round(V.VerAuf17/1000,2), 0) + nvl(round(V.VerAuf18/1000,2), 0) + nvl(round(V.VerAuf19/1000,2), 0) + nvl(round(V.VerAuf20/1000,2), 0) + nvl(round(V.VerAufKAPUn/1000,2), 0) + nvl(round(V.VerAufKAPVz/1000,2), 0) ), 0) Mandantenforderung,
nvl(sum(nvl(round(V.VerAuf4/1000,2), 0) ), 0) Inkassokosten,
nvl(sum(nvl(round(V.VerAuf5/1000,2), 0) ), 0) KontoFuehrungsgebuehren,
nvl(sum(nvl(round(V.VerAuf1/1000,2), 0) + nvl(round(V.VerAuf2/1000,2), 0) ), 0) Verwertungskosten,
nvl(sum(nvl(round(V.VerAuf10/1000,2), 0) + nvl(round(V.VerAuf8/1000,2), 0) + nvl(round(V.VerAuf9/1000,2), 0) ), 0) Barauslagen,
nvl(sum(nvl(round(V.VerAuf13/1000,2), 0) + nvl(round(V.VerAuf14/1000,2), 0) + nvl(round(V.VerAuf15/1000,2), 0) + nvl(round(V.VerAuf6/1000,2), 0) ),0) Gerichtskosten,
nvl(sum(nvl(round(V.VerAuf11/1000,2), 0) + nvl(round(V.VerAuf12/1000,2), 0) + nvl(round(V.VerAuf7/1000,2), 0) ), 0) RAKosten,
TO_CHAR(F.Created_Date,'MM.YYYY') Created_Date_MM ,
TO_CHAR(F.Created_Date,'YYYY') Created_Date_MMRRRR
FROM FACM F, VA V
WHERE F.custnum = DECODE(0,0,F.custnum,0) AND
F.accnum = V.accnum
GROUP BY F.custnum, V.Import_date,TO_CHAR(F.Created_Date,'MM.YYYY') ,TO_CHAR(F.Created_Date,'YYYY'))
Hello
Here's what I suggest:
select
a.custnum,
a.import_date,
b.ErledigtMM,
b.ErledigtGrundMM,
a.Mandantenforderung,
a.Inkassokosten,
a.KontoFuehrungsgebuehren,
a.Verwertungskosten,
a.Barauslagen,
a.Gerichtskosten,
a.RAKosten,
a.Created_Date_MM ,
a.Created_Date_MMRRRR
from (
SELECT F.custnum,
V.Import_date,
nvl(sum(nvl(round(V.VerAuf16/1000,2), 0) +nvl(round(V.VerAuf17/1000,2), 0) + nvl(round(V.VerAuf18/1000,2), 0) + nvl(round(V.VerAuf19/1000,2), 0) + nvl(round(V.VerAuf20/1000,2), 0) + nvl(round(V.VerAufKAPUn/1000,2), 0) + nvl(round(V.VerAufKAPVz/1000,2), 0) ), 0) Mandantenforderung,
nvl(sum(nvl(round(V.VerAuf4/1000,2), 0) ), 0) Inkassokosten,
nvl(sum(nvl(round(V.VerAuf5/1000,2), 0) ), 0) KontoFuehrungsgebuehren,
nvl(sum(nvl(round(V.VerAuf1/1000,2), 0) + nvl(round(V.VerAuf2/1000,2), 0) ), 0) Verwertungskosten,
nvl(sum(nvl(round(V.VerAuf10/1000,2), 0) + nvl(round(V.VerAuf8/1000,2), 0) + nvl(round(V.VerAuf9/1000,2), 0) ), 0) Barauslagen,
nvl(sum(nvl(round(V.VerAuf13/1000,2), 0) + nvl(round(V.VerAuf14/1000,2), 0) + nvl(round(V.VerAuf15/1000,2), 0) + nvl(round(V.VerAuf6/1000,2), 0) ),0) Gerichtskosten,
nvl(sum(nvl(round(V.VerAuf11/1000,2), 0) + nvl(round(V.VerAuf12/1000,2), 0) + nvl(round(V.VerAuf7/1000,2), 0) ), 0) RAKosten,
TO_CHAR(F.Created_Date,'MM.YYYY') Created_Date_MM ,
TO_CHAR(F.Created_Date,'YYYY') Created_Date_MMRRRR
FROM FACM F, VA V
WHERE F.custnum = DECODE(0,0,F.custnum,0) AND
F.accnum = V.accnum
GROUP BY F.custnum, V.Import_date,TO_CHAR(F.Created_Date,'MM.YYYY') ,TO_CHAR(F.Created_Date,'YYYY'))
) a,
FACM b
where b.custnum = a.custnum
By the way
WHERE F.custnum = DECODE(0,0,F.custnum,0) AND F.accnum = V.accnum
can be translated into
WHERE F.accnum = V.accnum
because
F.custnum = DECODE(0,0,F.custnum,0)
is always true
because
DECODE(0,0,F.custnum,0)
means
if 0=0 then F.custnum else 0
Tags: Database
Similar Questions
-
Concatenation of data with the GROUP BY clause
Hi again!
Following my previous thread...
I tried to apply the GROUP BY clause instead of preforming my query with RANK() to manage records NULL... I have a scenario where I also need to concatenate data from several lines.
CREATE TABLE T_EMP (NUMBER OF EMP_NO, NAME VARCHAR2 (20));
INSERT INTO T_EMP VALUES (1001, 'MARK');
INSERT INTO T_EMP VALUES (1002, 'DAVID');
INSERT INTO T_EMP VALUES (1003, "SHAUN");
INSERT INTO T_EMP VALUES (1004, "JILL");
CREATE TABLE T_EMP_DEPT (NUMBER OF EMP_NO, DEPT_NO NUMBER);
INSERT INTO T_EMP_DEPT VALUES (1001, 10);
INSERT INTO T_EMP_DEPT VALUES (1001, 20);
INSERT INTO T_EMP_DEPT VALUES (1002, 10);
INSERT INTO T_EMP_DEPT VALUES (1002, 20);
INSERT INTO T_EMP_DEPT VALUES (1002, 30);
INSERT INTO T_EMP_DEPT VALUES (1003, 20);
INSERT INTO T_EMP_DEPT VALUES (1003, 30);
INSERT INTO T_EMP_DEPT VALUES (1004, 10);
CREATE TABLE T_EMP_VISITS (NUMBER OF EMP_NO, DEPT_NO NUMBER, VISITED DATE);
INSERT INTO T_EMP_VISITS VALUES (1001, 10, 1 JAN 2009');
INSERT INTO T_EMP_VISITS VALUES (1002, 10, 1 JAN 2009');
INSERT INTO T_EMP_VISITS VALUES (1002, 30, 11 APR 2009');
INSERT INTO T_EMP_VISITS VALUES (1003, 20, 3 MAY 2009');
INSERT INTO T_EMP_VISITS VALUES (1003, 30: 14 FEB 2009');
COMMIT;
I have a T_EMP master table that stores the name and number of the emp. Each emp is required to visit some departments. This mapping is stored in the T_EMP_DEPT table. An employee can visit one or more departments. T_EMP_VISITS table stores the dates where the employee visited the services required. I need to view the report which should show when an employee all completed visits, which is the maximum date when it finished to visit all departments. If he did not visit any of the report should display date max, otherwise NULL. I was able to do using GROUP BY such proposed by Salim, but how do I show a list separated by commas of the services required for an employee in the same query.
SELECT
EMP_NO,
NAME,
MAX (DEPT_NO) KEEP (DENSE_RANK LAST ORDER BY VISITED) MAX_DEPT_NO,.
MAX (VISITED) KEEP (DENSE_RANK LAST ORDER PER VISIT) VISITS_COMP
DE)
SELECT
T_EMP. EMP_NO,
NAME,
T_EMP_DEPT. DEPT_NO,
VISITED
OF T_EMP
LEFT OUTER JOIN T_EMP_DEPT
ON T_EMP. EMP_NO = T_EMP_DEPT. EMP_NO
LEFT OUTER JOIN T_EMP_VISITS
ON T_EMP_DEPT. EMP_NO = T_EMP_VISITS. EMP_NO
AND T_EMP_DEPT. DEPT_NO = T_EMP_VISITS. DEPT_NO)
GROUP EMP_NO, NAME;
Output
EMP_NO NAME MAX_DEPT_NO VISITS_COMP
1001 MARK 20
1002 DAVID 20
1003 SHAUN 20 3 MAY 09
JILL 1004
Power required
EMP_NO NAME REQ_DEPTS MAX_DEPT_NO VISITS_COMP
1001 MARC 20 10.20
1002 DAVID 10,20,30 20
1003 SHAUN 20,30 20 3 MAY 09
JILL 10 1004
Can we do this in a single query?Hello
user512647 wrote:
... Sanjay
The query you provided that stragg() use seems to work but my requirement is not in the result set. I don't know how to use stragg with
MAX (DEPT_NO) KEEP (DENSE_RANK LAST ORDER BY VISITED) MAX_DEPT_NO,.
MAX (VISITED) KEEP (DENSE_RANK LAST ORDER PER VISIT) VISITS_COMP
I need more, these two columns these gives me the date when they have completed all visits. If they missed any Department then the result must be NULL in the VISITS_COMP field.Just add them to the SELECT clause:
SELECT t_emp.emp_no, name, STRAGG (t_emp_dept.dept_no) AS deptno, MAX (t_emp_dept.dept_no) KEEP (DENSE_RANK LAST ORDER BY visited) AS max_dept_no, MAX (visited) AS visits_comp FROM t_emp LEFT OUTER JOIN t_emp_dept ON t_emp.emp_no = t_emp_dept.emp_no LEFT OUTER JOIN t_emp_visits ON t_emp_dept.emp_no = t_emp_visits.emp_no AND t_emp_dept.dept_no = t_emp_visits.dept_no GROUP BY t_emp.emp_no , name ;
The column called visit_comp is simply the last visited, regardless of how the employee visited departments.
If you want to have the NULL value if the employee has not yet visited all 3 departments:... CASE WHEN COUNT (DISTINCT t_emp_dept.dept_no) = 3 THEN MAX (visited) END AS visits_comp
The 'magic number' 3 is the total number of departments.
If you want to understand the correct value of that at the time of the execution of the query, replace the code literal 3 hard with a scalar subquery.Note that 'KEEP MAX (x) (DENSE_RANK OVER LAST SERVICE BY x)' (where the exact same column is used as an argument and that the ORDER BY column) is just "MAX (x)".
-
A question about the analytical function used with the GROUP BY clause in SHORT
Hi all
I created the following table named myenterprise
If I want to find which is the total sales by city? I'll run the following queryCITY STOREID MONTH_NAME TOTAL_SALES ---------- ---------- ---------- ---------------------- paris id1 January 1000 paris id1 March 7000 paris id1 April 2000 paris id2 November 2000 paris id3 January 5000 london id4 Janaury 3000 london id4 August 6000 london id5 September 500 london id5 November 1000
that works very well and produces the expected result, i.e.SELECT city, SUM(total_sales) AS TOTAL_SALES_PER_CITY FROM myenterprise GROUP BY city ORDER BY city, TOTAL_SALES_PER_CITY;
Now in one of my books SQL (Mastering Oracle SQL) I found another method by using the SUM, but this time as an analytic function. Here's what the method of the book suggests as an alternative to the problem:CITY TOTAL_SALES_PER_CITY ---------- ---------------------- london 10500 paris 17000
I know that the analytic functions are executed after the GROUP BY clause has been transformed completely and Unlike regular aggregate functions, they return their result for each line belonging to the partitions specified in the partition clause (if there is a defined partition clause).SELECT city, SUM(SUM(total_sales)) OVER (PARTITION BY city) AS TOTAL_SALES_PER_CITY FROM myenterprise GROUP BY city ORDER BY city, TOTAL_SALES_PER_CITY;
Now my problem is that I do not understand what we have to use two functions SUM? If we only use one only, i.e.
This generates the following error:SELECT city, SUM(total_sales) OVER (PARTITION BY city) AS TOTAL_SALES_PER_CITY FROM myenterprise GROUP BY city ORDER BY city, TOTAL_SALES_PER_CITY;
The error is generated for the line 2 column 11 which is, for the expression SUM (total_sales), well it's true that total_sales does not appear in the GROUP BY clause, but this should not be a problem, it has been used in an analytical function, so it is evaluated after the GROUP BY clause.Error starting at line 2 in command: SELECT city, SUM(total_sales) OVER (PARTITION BY city) AS TOTAL_SALES_PER_CITY FROM myenterprise GROUP BY city ORDER BY city, TOTAL_SALES_PER_CITY Error at Command Line:2 Column:11 Error report: SQL Error: ORA-00979: not a GROUP BY expression 00979. 00000 - "not a GROUP BY expression" *Cause: *Action:
So here's my question:
Why use SUM (SUM (total_sales)) instead of SUM (total_sales)?
Thanks in advance!
:)
In case you are interested, that's my definition of the table:
Edited by: dariyoosh on April 9, 2009 04:51DROP TABLE myenterprise; CREATE TABLE myenterprise( city VARCHAR2(10), storeid VARCHAR2(10), month_name VARCHAR2(10), total_sales NUMBER); INSERT INTO myenterprise(city, storeid, month_name, total_sales) VALUES ('paris', 'id1', 'January', 1000); INSERT INTO myenterprise(city, storeid, month_name, total_sales) VALUES ('paris', 'id1', 'March', 7000); INSERT INTO myenterprise(city, storeid, month_name, total_sales) VALUES ('paris', 'id1', 'April', 2000); INSERT INTO myenterprise(city, storeid, month_name, total_sales) VALUES ('paris', 'id2', 'November', 2000); INSERT INTO myenterprise(city, storeid, month_name, total_sales) VALUES ('paris', 'id3', 'January', 5000); INSERT INTO myenterprise(city, storeid, month_name, total_sales) VALUES ('london', 'id4', 'Janaury', 3000); INSERT INTO myenterprise(city, storeid, month_name, total_sales) VALUES ('london', 'id4', 'August', 6000); INSERT INTO myenterprise(city, storeid, month_name, total_sales) VALUES ('london', 'id5', 'September', 500); INSERT INTO myenterprise(city, storeid, month_name, total_sales) VALUES ('london', 'id5', 'November', 1000);
It is clear that thet Analytics is reduntant here...
You can even use AVG or any analytic function...SQL> SELECT city, 2 avg(SUM(total_sales)) OVER (PARTITION BY city) AS TOTAL_SALES_PER_CITY 3 FROM myenterprise 4 GROUP BY city 5 ORDER BY city, TOTAL_SALES_PER_CITY; CITY TOTAL_SALES_PER_CITY ---------- -------------------- london 10500 paris 17000
-
How to select the group header with detailed data in a SQL
Dear Sir
I wish I had a little help from you. My goal is to create a view where the data should be in the appropriate format. In this format, I want to have for each header of a group.
I have 3 tables that they ar connected to the other (representing hierarchical data where financial plan breaks in different groups).
CRM_PLAN
CRM_PLAN_ID
DATE
AMOUNT
CRM_PLAN_PE
CRM_PLAN_PE_ID
TITLE
AMOUNT
CRM_PLAN_ID (REF CRM_PLAN key. CRM_PLAN_ID)
CRM_PLAN_MONTH
CRM_PLAN_MONTH_ID
YEAR
MONTH
AMOUNT
CRM_PLAN_PE_ID (foreign key to CRM_PLAN_PE. CRM_PLAN_PE_ID)
Data looks like:
CRM_PLAN
CRM_PLAN_ID | DATE | AMOUNT
1. 01.01.2012. 500
2. 01.02.2012 | 200
CRM_PLAN_PE
CRM_PLAN_PE_ID | TITLE | AMOUNT | CRM_PLAN_ID
1. Organization 1. 100. 1
2. Organization 2. 400. 1
5: 3 organization | 200 | 2
CRM_PLAN_MONTH
CRM_PLAN_MONTH_ID | YEAR | MONTH | AMOUNT | CRM_PLAN_PE_ID
1. 2012 | 1. 60. 1
2. 2012 | 2. 40. 1
5: 2012 | 1. 350. 2
4. 2012 | 2. 50. 2
3: 2012 | 1. 200 | 3
I would like to than the view that returns data as:
MONTH | AMOUNT
Organization 1. null
1. 60
2. 40
Organization 2. null
1. 350
2. 50
3 organization | null
1. 200
The main question is hot to write a sql as source for display to insert before each group a line with the value of the title of the table CRM_PLAN_PE column. Is it still possible? Perhaps you could suggest another method.
Notice will be used in the form of oracle where will be possible to change the data - I will make the necessary arrangements by trigger INSTEAD of.
Kind regards
Igor
Published by: user5528050 on 29.11.2012 02:23
Published by: user5528050 on 29.11.2012 02:24
Published by: user5528050 on 29.11.2012 02:25Hi, Igor,.
In this case, I think ROLLUP is a little simpeler GROUPING SETS, but you could do it anyway:
SELECT CASE WHEN GROUPING (tab2.id) = 0 THEN TO_CHAR (tab2.id) ELSE tab1.title END AS col_1 , SUM (tab2.amount) AS col_2 FROM tab1 JOIN tab2 ON tab1.id = tab2.tab1_id GROUP BY tab1.title , ROLLUP (tab2.id) ORDER BY tab1.title , GROUPING (tab2.id) DESC , tab2.id ;
If tab2.id cannot be NULL, you can use
NVL ( TO_CHAR (tab2.id) , tab1.title )
instead of the CASE expression and simplify the ORDER BY clause to
ORDER BY tab1.title , tab2.id NULLS FIRST
-
CFQUERYPARAM tag does not work in the GROUP BY clause
I get an error whenever I put a CFQUERYPARAM tag in a GROUP BY clause. I saw on another forum, someone had a similar problem with the ORDER BY clause
Here's a sample of what might look like my code
Select x, y, z of ABC
Group of < cfqueryparam value = 'x' cfsqltype = "cf_sql_float" >
Here is the error I get.
Run database query error.
[Macromedia] [Oracle JDBC Driver] [Oracle] ORA-00979: not a GROUP BY expression
Any idea?Cachedwithin and cachedafter functions store the query results in the RAM of the server. This means that, even if it is cached, when you run it, you get the cached result instead of going to the database to run again. This increases the speed of course, but if the data is changed during the period of cover, you have accuracy problems.
It creates no memory problems. In the administrator you book a certain amount of memory for the query cache. If you exceed this amount, the last request to shoot the first query on, or something like that.
In regards to what you're trying to do on the binding of variables to your group by clause, this isn't what cfqueryparam has been designed for. It has been designed to
where clauses (where it =
or insert queries (insert in my values in the table (field) ())
and things like that.You try to use it for anything other than what it was designed for, which explains why it does not work for you.
-
Adding columns in the group by clause
Hello
My query is like this,
Select empid, sum (sal) in the group by empid emp,
I want additional columns to be included in the request
Select empid, address, sum (sal) in the group by empid
Is there a possible way to include the other columns outside the group by column.
Thank youHi, you can write like this
select a.empid,e.address,a.sal from( select empid , sum(sal)as sal from emp group by empid )a ,emp e where a.empid=e.empid
Published by: user10736825 on January 25, 2010 12:59
-
NEED HELP IN THE GROUP BY CLAUSE CASES PLEASE
User1983440 thanks for the help with the script below grouped by product category, can you or someone else help me group by another Case statement as well.
WITH p AS)
Select distinct
partner, region, od. ORDER_AFFILIATE_NAME,
Oh.external_order_number,
Ain.get_g1 (queue_type) offers,
Case
When disp.category = 100 Then 'ORDER'
When disp.category = 200 Then 'ACCESS'
When disp.category = 300 Then 'DSL'
When disp.category = 600 Then 'IPTV'
"When disp.category = 700 Then'INTERNET"
When disp.category = 800 Then 'VOIP'
End up like product_category,
To_char(OH.created_ts, 'yyyy-mm-dd HH24:mi:ss') CREATE_DATE
-Case when ip.offer_type = "IPDSLAM" or instr (ip.display_name, "-d") > 0
THEN 'IP - LAN'
ELSE 'FTTN.
end as product_type
Case
When disp.state = 4 and disp.state = 9 or disp.state = 21 or 22 = disp.state then 'cancelled '.
When disp.state = 17 then "NRFC cancelled.
When disp.state = 7 Then 'incomplete '.
When disp.state = 3 or disp.state = 8, then "Finish".
When disp.state = 6 or disp.state = 10 and disp.state = 13 or disp.state = 14 then 'pending - other ".
When disp.state = 19 disp.state = 20 then "sent".
When disp.state = 21 or disp.state = 22 then "Cancelled - CSUS.
When disp.state = 23 or 24 = disp.state then 'Order Confirmation '.
When disp.state = 1 or disp.state = 2 or disp.state = 15 then "receipt".
Another 'other '.
End as STATE_desc
of AIN.impl_oh_order_header oh,.
Ain.impl_order_data od,
DISP AIN.sncr_order_curr_disp,
AIN.impl_package ip
where oh.created_ts between to_date ('2013-02-04', ' yyyy-mm-dd "")
and to_date ('2013-02-11', ' yyyy-mm-dd "")
and oh.order_type = 'COMMAND '.
and disp.category to (200, 300, 600, 700, 800)
and disp.state! = '5'
and uscs = 0
and disp.transaction_id = oh.transaction_id
and od. transaction_id = oh.transaction_id
and ip.transaction_id = oh.transaction_id
and ip.package_type = 'PACKAGE '.
and ip.parent_package_id is null
and ip.product_type = 'COMMAND '.
)
SELECT product_category,
COUNT (*)
P
GROUP BY product_categoryTo summarize, by category of product, and then by state_desc:
WITH p AS ( Select distinct partner, region, od.ORDER_AFFILIATE_NAME, oh.external_order_number, ain.get_g1(queue_type) offer, Case When disp.category = 100 Then'ORDER' When disp.category = 200 Then'ACCESS' When disp.category = 300 Then'DSL' When disp.category = 600 Then'IPTV' When disp.category = 700 Then'INTERNET' When disp.category = 800 Then'VOIP' End as product_category, TO_CHAR(oh.created_ts, 'yyyy-mm-dd hh24:mi:ss') CREATE_DATE, Case when ip.offer_type = 'IPDSLAM' or instr(ip.display_name, '- D')> 0 THEN 'IP-DSL' ELSE 'FTTN' end as product_type, Case When disp.state = 4 or disp.state = 9 or disp.state= 21 or disp.state= 22 Then 'Canceled' When disp.state = 17 Then 'Canceled NRFC' When disp.state = 7 Then 'Incomplete' When disp.state = 3 or disp.state = 8 Then 'Complete' When disp.state = 6 or disp.state = 10 or disp.state = 13 or disp.state =14 Then 'Pending - Other' When disp.state = 19 or disp.state = 20 Then 'Submitted' when disp.state = 21 or disp.state = 22 then 'Cancelled- CSUS' when disp.state =23 or disp.state = 24 then 'Order Confirmation' when disp.state =1 or disp.state = 2 or disp.state = 15 then 'Received' Else 'Other' End as STATE_desc from AIN.impl_oh_order_header oh, ain.impl_order_data od, AIN.sncr_order_curr_disp disp , AIN.impl_package ip where oh.created_ts between to_date('2013-02-04', 'yyyy-mm-dd') and to_date('2013-02-11', 'yyyy-mm-dd') and oh.order_type = 'ORDER' and disp.category in (200, 300, 600, 700, 800) and disp.state !='5' and uscs= 0 and disp.transaction_id = oh.transaction_id and od. transaction_id = oh.transaction_id and ip.transaction_id = oh.transaction_id and ip.package_type = 'PACKAGE' and ip.parent_package_id is null and ip.product_type = 'ORDER' ) SELECT product_category, STATE_desc, COUNT(*) FROM p GROUP BY product_category, STATE_desc
To summarize by state_desc, just remove "product category", the query above.
-
I can't select the groups in my outlook account
under the head of the people, next to the used button it have a drop-down menu to select groups. but I'm unable to find these days.
Hey Monty,
Are you referring to Microsoft Outlook or Outlook.com?
If you use Microsoft Office Outlook, then I suggest you according to the query in Microsoft Office Forum for better support.
Reference:
http://answers.Microsoft.com/en-us/Office/Forum/Outlook
If you are referring to Outlook.com, then send the application in the Windows Live Forum for assistance:.
Reference:
http://answers.Microsoft.com/en-us/windowslive/Forum/mail
I hope this helps. If you have any other queries/issues related to Windows, write us and we will be happy to help you further.
-
I have a table that is defined as follows.
unique_number NOT NULL VARCHAR2 (64).
input_unique_number VARCHAR2 (64).
source_system VARCHAR2 (40),
end_system VARCHAR2 (40),
type VARCHAR2 (32),
date_time_sent TIMESTAMP (6).
transaction_name VARCHAR2 (60)
type input, output and does not
For each input message that a unique_number is generated, it will be populated source_sytem value but not end_sytem value
For each output message a unique_number is generated and will be input_unique_number identical to that of the input message.
For each message output of the values source_system and end_system are met.
I am trying to create a report that will give the entry, exit and County having failed for each end site, but output is to get the empty ID for the input_messages
Select
Count (case when ' entry', then Unique_id) end as I have.
(type of case when 'out' then end Unique_id) be counted as O,.
count (type of case when 'failed' then end Unique_id) f.
transaction_name,
end_system
of message_table
where to_char (date_time_sent, "DD-MON-YY HH24:MI:SS) between May 18, 11% 09' and 19 May 11 11% '
and source_system = '& Source_system'
Transaction_name group, end_system
ORDER BY end_system;
I got the following result
I O F TRANSACTION_Name END_SYSTEM
---------------------------------------------------------------------------
0 11 0 DistProdQualityEvent EANCM5051256614152
11 0 22 DistProdQualityEvent EANCM
1 0 0 DistInventoryReport EANCM5051351029368
1 0 DistInventoryReport 0 EANCM
But I'm trying since release something like that
I O F TRANSACTION_Name END_SYSTEM
---------------------------------------------------------------------------
22 11 11 DistProdQualityEvent EANCM5051256614152
1 1 0 DistInventoryReport EANCM5051351029368
Can you please let me know is a such output is possible or notWithout seeing the underlying data, it is difficult to be sure, but I guess that this is due to later...
(1) entry has no match messages and messages that fail don't have not populated end_system: it seems that this is the case for BatchCntrlNotify, NotifyProductCatalog and NotifyShippingOrder
(2) input messages do not correspond to output messages or down: it seems that this is the case for OAGSyncCustPartyMaster and POConfirmationOnly in case you released successful message that you have an end_system.
Published by: Malloy June 7, 2011 03:58
-
PS Query - subtraction in the Group By Clause
Hello!!!
I have according to requirement. My PS query is seen 3 columns with the following values.
Col1 Col2 Col3
K1 8 2
K1 8 2
K1 8 2
Requirement was to have the sum of Col3. So I modified the query using SUM (Col3) as aggregate expression. Now my output looks like
Col1 Col2 Col3
K1 8 6
Now... I want the 4th column that will be the Col2 - Col3 subtraction so that the output looks like
Col1 Col2 Col3 Col4
K1 8 6 2
I use VIEW and implement this but I want to know if this can be achieved using the PS query. I also tried to use expression but his does not work.
You should be able to create an expression.
Check the aggregation function on the output Expression property page and enter the Expression as text
Max (col2) - Sum (Col3)
and, of course, define the properties of Type of the Expression and the length of the appropriate values.
Kind regards
Bob
-
Select the statement and the Group of
Hi all
I have this code to display the total number of orders by customer id:
Select customer_id, sum (order_total) total
of demo_orders
Customer_id group;
and it gives me this result:
CUSTOMER_ID TOTAL
----------- ----------
1 2380
2 2370
3 2420
4 1060
5 1090
6 950
7 2760
7 selected lines.
But instead of the ID, I want to display their names, like this:
CUSTOMER TOTAL
Brown, John 3450
... and so on
How do I do that?
I know I can't include these columns concatenated in the selection list, because I would have to be included in the GROUP BY clause...
Thank you.
I know I can't include these columns concatenated in the selection list, because I would have to include it in the
Huh? Why not you. Have you actually tried it?
Just do what you say - include names concatenated in the select group of clauses.
Or you can just join the query you have each other to get the names, since we have no idea where the names are still stored. If they are in the same table as the ID then just use the solution "you know you can't do '!
-
Why can I not select the entire Repeater object?
I have a feeling that it is a simple question:
I use a Mac Pro with 10.10.5 and AE 2015.0.1 Release.
When I add a Repeater to a shape layer, I can not select the Group of repeated objects (via the bounding box) ('parent' and 'children'). It only allows me to choose the parent.
I'm doing something wrong here? Something uncontrolled?
I want to create long shapes and manipulate in 3d, but I'd really rather not do the whole thing just to be able to elect the parent object.
Change this behavior in CC. If you want to see all the layers in a selection box, then you must either wait for a update or work on the CS6. Because I saw blue, I thought that you have been affected by a change in behavior in CC or newer. Personally, especially when forms are complex, I find it easier to be able to discern the basic form so I can double click and edit just this form.
-
Can not find a way to bypass the Group
The following query runs as is, but only because I have included IntervForcl, IsSpecial , in the group by clause. I don't want group by these things, that month. I have no idea how to write this query, do what I want, I tried everything. Any suggestion would be appreciated.
The end result is supossed to look something like this:
PostedDate RushMargin NonRushMargin InteriorMargin
2013.01 65.4% 42% 21.5%
2013.02 62.7% 43.5% 32%
2013.03 67.3% 41.1% 29.8%
SELECT CONVERT (varchar (7), APPostedWhen, 102) AS [PostedDate].
[InteriorMargin] = BOX
WHEN intervforcl = 'k' THEN CAST (((APAMOUNT) AVG / AVG (ARAMOUNT)) * 100 AS DECIMAL (12,2))
END,
[RushMargin] = BOX
WHEN IsSpecial = '1' CAST (((APAMOUNT) AVG / AVG (ARAMOUNT)) * 100 AS DECIMAL (12,2))
END,
[NonRushMargin] = BOX
WHEN IsSpecial <>'1' THEN CAST (((APAMOUNT) AVG / AVG (ARAMOUNT)) * 100 AS DECIMAL (12,2))
END
Inspections
WHERE DATEDIFF (MONTH, APPostedWhen, SYSDATETIME ()) < 6 AND ARAMOUNT > 0 AND APAMOUNT > 0
GROUP OF CONVERT (varchar (7), APPostedWhen, 102)IntervForcl, IsSpecial
ORDER BY [PostedDate]
It is a forum for oracle pl/sql.
What you think you have TSQL.
However we need conditions case inside aggregate functions, I guess.
as
CAST ((AVG (affaire quand intervforcl = 'k' alors fin APAMOUNT) / AVG (case...)) (ARAMOUNT)) * 100 AS DECIMAL (12,2))
and so on.
Be careful on the way in which the aggregate function deal with NULL values.
-
missing parenthesis in insertion into separate lines select the table from the other table
Hello
could you help me with the following question?
I have the following tables
CREATE TABLE table1)
ID varchar (12),
col2 varchar (10),
COL3 varchar (10),
level varchar (10))
CREATE TABLE table2)
Id2 varchar (12)
A varchar (10),
B number (1)
CONSTRAINT PRIMARY KEY PK (ID2, is));
INSERT INTO table2 (ID2, A, B) SELECT ID, col2
MAX (CASE WHEN level = "level 1" then 1
level = 'level 2' then 2
Level = 3 then 'niveau3') as colIN3)
FROM table1 GROUP BY ID2, a.;
the first table have duplicates as follows:
Id2 COL2 COL3 level
A1 pepe football level1
A1 pepe football level2
A1 pepe football level1
A1 pepe basket level2
A1 pepe pingpong level3
the output should be selected with unique key (ID2, col3) lines and the level must be the greatest.
Id2 COL2 COL3 level
A1 pepe football level2
A1 pepe basket level2
A1 pepe pingpong level3
The output of the script tells me the following messages:
-lack of right parenthesis referring to the max function.
Thanks adavance.
Kind regards
Hello
Remember the ABC's of the GROUP BY:
When you use a GROUP BY clause or in an aggregate function, then all in the SELECT clause must be:
(A) a ggregate function,
(B) one of the expressions "group By."
(C) adding to C, or
(D) something that Depends on the foregoing. (For example, if you "GROUP BY TRUNC (dt)", you can SELECT "TO_CHAR (TRUNC (dt), 'Mon - DD')").
To ask him, there are 5 columns in the SELECT clause. The last one is a function MAX (...); It is an aggregate, is not serious.
The first 2 columns are also named in the GROUP BY clause, so that they are well.
The other 2 columns, country and internal_Id do not match any of the above categories. These 2 columns cause the error.
There are many ways to avoid this error, each producing different results. You could
- remove these 2 columns in the SELECT clause
- Add these 2 columns in the GROUP BY clause
- use the aggregation such as MIN, 2-column functions
- remove the country from the SELECT clause and add internal_id to the GROUP BY clause
- remove the internal_id from the SELECT clause, and add countries to the GROUP BY clause
- ...
What are the results you want?
Whenever you have a question, please post a small example of data (CREATE TABLE and INSERT statements) for all the tables involved, so people who want to help you can recreate the problem and test their ideas. Also post the results you want from this data, as well as an explanation of how you get these results from these data.
Always say what version of Oracle you are using (for example, 11.2.0.2.0).
See the FAQ forum: https://forums.oracle.com/message/9362002
-
Problem with my account and the Group of
Hey there,
I have some difficulties to group by my result, and I ask for assistance in this forum.
My table is really simple, have an Ilie and a COM domain that contain the string with line breaks. I want to count the number of group ResId by COM.
My data in my table store have look like this:
RESOURCE TABLE:
ResId. COM
1. Server: Walcot15.\nCOD M50
2. Server: Walcot15.\nCOD M55
3. Server: Walcot16.\nCOD M55
I would like to get as a result:
Count (RESID) | COM
2. Server: Walcot15.
1. Server: Walcot16.
First of all, I did substr in order to keep only the string that contains the server and not the \nCOD...
SELECT
County (RES. (' ' ID ') as "ResId".
substr (RES. CMT, 0, instr (RES. CMT, Chr (10))) as 'COM '.
Of
RES THE RESOURCE
WHERE
REGEXP_LIKE (RES. ("' CMT ', 'Server', 'i')
Group (RES. "" THE ID ", RES. CMT)
order by
1
The problem is not count and group by server. Anyone help me, please?
Kind regards
Jarod.Hello
When you assign a column alias (for example, COM) in a query, you can't reference this alias in the same query (except in the ORDER BY clause). It is necessary to repeat the expression or affect the aliases in a subquery. Then, you can use the alias in any part of the request of the mother.
For example:WITH got_com AS ( SELECT id , SUBSTR ( cmt , 1 , INSTR (cmt, '\') - 1 ) AS com -- Alias defined FROM resources WHERE INSTR ( UPPER (cmt) , 'SERVER' ) > 0 ) SELECT COUNT (id) AS count_resid , com -- Alias referenced FROM got_com GROUP BY com -- Alias referenced ORDER BY com -- Alias referenced ;
Output:
COUNT_RESID COM ----------- ------------------------------ 2 Server : Walcot15. 1 Server : Walcot16.
If the idea is to have a production line for evry value distinct from com, the GROUP BY clause should not contain anything except com
You will notice that I used SUBSTR and INSTR, above, in the places where you can also use regular expressions. This is because regular expressions tend to be much slower. If the speed is not a problem, and you prefer to use REGEXP_SUBSTR or REGEXP_LIKE, then it is fine to use.
Maybe you are looking for
-
Photos crashes when you try to share by any means
Hello I recently encountered a problem with the Photos app. When I click on the share button, the application crashes. It is only possible to close directly by means of clicking the icon in the dock and chasing quit option. How to solve this problem?
-
administrative user name and password on ex6200 changes
I currently have my netgear ex6200 in the default configuration to expand my wifi network. How can I change the administrator username and password?
-
How to read and write attributes using the API?
I'm trying attributes of access (read and write) of the following: SequenceFile Sequence The sequence steps When you look at the documentation of the API, TestStand, the following functions are available: PropertyObject Properties Attributes (read-on
-
Fatal error system stoppedCnu9293p33
-
Timed software a generation of impulses - USB-6009
Hello. I searched for a reliable way to produce a pulse point by point with the USB-6009. My question is whether or not it is possible to produce such a signal without hardware timing or a counter as the USB-6009 supports neither. Is the closest I've