PowerBI - Help with a nested join
Hello:
I am relatively new to PowerBI and am trying to optimize my queries. Can you please advise on one or both questions below?
1. I have two external data sources, both SQL Server. I created two queries - one gets all students with a lastname starting with a letter and the second gets all students living in a certain state. I want to join the results of both queries which are pulling
from the same table. The result of my query is as below:
let
Source = Sql.Database("server", "database", [Query="select * from students where state = 'ca'"]),
Merge = Table.NestedJoin(Source,{"LastName"},NameQuery,{"LastName"},"NewColumn",JoinKind.Inner)
in
Merge
The net result of this according to SQL profiler is that it pulls all 20,000 records for the name query and all 50,000 records for the state query and then appears to merge them in PowerQuery. I was expecting that the merge / join would pass this query down
to the database and do the join there instead. Perhaps I missed a step in setting up the Query.
2. Assuming #1 is possible, what if I wanted to achieve the same behavior with OData? Although I am very familiar with the OData filter syntax, how setting up the relationship in PowerQuery and pre-generating the query seems like it would not be possible
but that's why I am looking for answers!
Thanks.
Thank you for the response(s).
Can we dive just a bit deeper? Instead of specifying a query, I added just the connection and database. In the navigator I chose a view and created a connection (only) from it. I filtered this view (in PQ) to only return columns that matched a given value.
I then created another query using the same connection as above and did a merge against my first dataset on the rowkey column in order to get the filtered result. I did not specify any queries. The result was still two queries, one filtered one not versus
a singular query joined at the keys.
For OData I am gathering that you are saying that my service has to include the columns through something like the expand method. Is there any documentation you can point me to regarding query generation of OData endpoints in Power BI?
Similar Messages
-
Help with corrupted nested sequences.
First off, let me say that next project I'm going with Avid.
I have been using nested sequences as sparingly as possible on a long, complicated project, but the few that I have are prone to getting "corrupted" (this is the technical term that Kevin Monahan from Adobe has used to describe what's happening). So it's been recommended that I replace the corrupted sequence. Sure I can just copy the material in the corrupted sequence and place it in a new sequence, but how can I do this without loosing my HOURS of edits with this nested sequence in my main timeline?
Thanks,
Steve KellerHave you got a backup of your original photos? If so then you can
recreate the catalogue very easily in less than 5 minutes. PSE always
leaves photos in their original location. they are not moved at all.
One should always backup photos, videos, documents, emails etc
separately from applications that created them in the first place.
Disasters happen and we can't always protect from them except to backup
as taught in computing 101 class. -
I have the following query which has an outer join and it works perfectly and shows publication paragraph which don't have any maintenance records with a value of 0.
However when I add to the where clause conditions such as lpm.fac_ident and lpm.start_date, the null values no longer show up in the query(see second SQL statement).
I am new at SQL and am just trying to make this outer join work. Any help would be appreciated.
-- THIS WORKS
SELECT m.publication_paragraph, pm.description, pm.frequency, count(l.publication_paragraph) ACTIVITIES_PERFORMED
FROM lpm_paragraph_mapping_table m, lpm l, pm_requirements_table pm
WHERE m.paragraph_alias_mapping = l.publication_paragraph (+)
GROUP BY m.publication_paragraph, pm.description, pm.frequency
order by count(l.publication_paragraph);
-- THIS DOES NOT WORK
SELECT m.publication_paragraph, pm.description, pm.frequency, count(l.publication_paragraph) ACTIVITIES_PERFORMED
FROM lpm_paragraph_mapping_table m, lpm l, pm_requirements_table pm
WHERE m.paragraph_alias_mapping = l.publication_paragraph (+)
AND l.fac_ident = 'EWR' AND TO_CHAR(l.start_date, 'YYYY') = '2010'
GROUP BY m.publication_paragraph, pm.description, pm.frequency
order by count(l.publication_paragraph);
Edited by: George Heller on Jun 30, 2011 9:47 AMfabio_silva wrote:
Hi,
I just didn't get. The table (pm_requirements_table pm) haven't any join ???
Regards,Forgive the ASCII art, but your query looks like:
---------- JOIN ----------
| Alias M | ====> | Alias L |
| Alias PM |
----------- The table pm_requirements_table is not joined at all. Unless it has only a single row, then your resultset will have 1 row for each row in lpm_paragraph_mapping_table (because of the outer join) times the number of rows in pm_requirements_table. Consider this simplified example.
SQL> select * from t;
ID DESCR
1 T 1
2 T 2
SQL> select * from t1;
ID DESCR
1 T1 1
2 T1 2
3 T1 3
4 T1 4
SQL> select 1.id, t.descr, t1.descr
2 from t, t1;
ID DESCR DESCR
1 T 1 T1 1
1 T 1 T1 2
1 T 1 T1 3
1 T 1 T1 4
1 T 2 T1 1
1 T 2 T1 2
1 T 2 T1 3
1 T 2 T1 4Here, my table t is the result from your join between lpm_paragraph_mapping_table and lpm. My table t1 is your pm_requirements_table. You need something more like:
SQL> select 1.id, t.descr, t1.descr
2 from t, t1
3 where t.id = t1.id;
ID DESCR DESCR
1 T 1 T1 1
1 T 2 T1 2Assuming you fix that join, you can use a sub-query to apply the predicates to the lpm as Centinul showed, or, if you are on a current version of Oracle, use ANSI join syntax wich would look something like:
SELECT m.publication_paragraph, pm.description, pm.frequency,
count(l.publication_paragraph) ACTIVITIES_PERFORMED
FROM lpm_paragraph_mapping_table m,
LEFT JOIN lpm l,
ON m.paragraph_alias_mapping = l.publication_paragraph and
l.fac_ident = 'EWR' AND
TO_CHAR(l.start_date, 'YYYY') = '2010'
JOIN pm_requirements_table pm
on something
GROUP BY m.publication_paragraph, pm.description, pm.frequency
ORDER BY count(l.publication_paragraph);Leaving aside the missing join, the reason why your query as posted does not work is that when there is not a match on m.paragraph_alias_mapping = l.publication_paragraph Oracle will "make up" rows form lpm with all null columns for each row in lpm_paragraph_mapping_table where there is no match. So, when you compare those made up rows from lpm, you are effectively saying where NULL = 'EWR' and TO_CHAR(NULL, 'yyyy') = '2010'. Null is never equal to anything. Any comparision against null is unknown, so the made up rows get filtered out by your predicate.
John -
ABAP help with deeply nested items.
Gurus,
We have a requirement whence we need to sum up the key figures from one transformation layer going to the next. The challenge is, its a deeply nested structure. something like :
SalesOrderItem Higher Level Item KeyFig
1000 0000 30
1010 1000 20
1011 1010 10
1015 1010 20
1020 1010 20
1021 1020 10
1022 1020 50
1023 1020 10
1025 1020 20
So now, in the next layer we will be rolling it upto the 1000 , 2000...levels- in this example 1000 level only.
The round figure items(1010, 1020.....) are the individual kmats and the summation happens like this:
1. Items 1021, 1022, 1023 and 1025 roll up to 1020; sum = 90.
2. Now when 1020 rolls up to its higher level item which is 1010, the sum that rolls up from 1020 should be 90 + 20.
3. Ultimately when all items roll up to item 1000, the total sum will be 190.
Can someone please help me write this logic in ABAP?
Thanks!
ChrisYou can try this, but please put it through more examples. Assumption is that your highest level item will have higher item number as 0000 and that they are always sorted in the way it is given in your example.
DATA: BEGIN OF itab OCCURS 0,
posnr(6) TYPE n,
uposn(6) TYPE n,
qty TYPE p DECIMALS 2.
DATA: END OF itab.
DATA: itab2 LIKE itab OCCURS 0 WITH HEADER LINE.
DATA: itab3 LIKE itab OCCURS 0 WITH HEADER LINE.
DATA: v_total TYPE p DECIMALS 2,
v_posnr(6) TYPE n.
itab-posnr = '1000'.
itab-uposn = '0000'.
itab-qty = 30.
APPEND itab.
itab-posnr = '1010'.
itab-uposn = '1000'.
itab-qty = 20.
APPEND itab.
itab-posnr = '1011'.
itab-uposn = '1010'.
itab-qty = 10.
APPEND itab.
itab-posnr = '1015'.
itab-uposn = '1010'.
itab-qty = 20.
APPEND itab.
itab-posnr = '1020'.
itab-uposn = '1010'.
itab-qty = 20.
APPEND itab.
itab-posnr = '1021'.
itab-uposn = '1020'.
itab-qty = 10.
APPEND itab.
itab-posnr = '1022'.
itab-uposn = '1020'.
itab-qty = 50.
APPEND itab.
itab-posnr = '1023'.
itab-uposn = '1020'.
itab-qty = 10.
APPEND itab.
itab-posnr = '1025'.
itab-uposn = '1020'.
itab-qty = 20.
APPEND itab.
itab2[] = itab[].
*-- assumption is that if UPOSN = 000000, then there is no higher level
* item
LOOP AT itab WHERE uposn = '000000'.
itab3-posnr = v_posnr = itab-posnr.
DO.
LOOP AT itab2 WHERE uposn = v_posnr.
v_total = v_total + itab2-qty.
ENDLOOP.
IF sy-subrc <> 0.
EXIT.
ELSE.
v_posnr = itab2-posnr.
ENDIF.
*-- This item does not appear as a higher level item
ENDDO.
v_total = v_total + itab-qty.
itab3-qty = v_total.
APPEND itab3.
CLEAR itab3.
ENDLOOP.
LOOP AT itab3.
WRITE:/ itab3-posnr,
itab3-qty.
ENDLOOP. -
Help with my nested loop...
this application allows a user to enter two int values, rows(height) and columns(length), that are used to create a box of asterisks.
my createBox() does not work correctly, only prints first line, loops infinitely, or doesnt loop. can someone help me out please?
import java.io.*;
public final class AsteriskBox
/****InstanceVariables****/
public static int row;
public static int col;
/****Constructor()****/
public AsteriskBox()
/****Access()'s****/
public void createBox(int x, int y)
if((x > 0) && (y > 0))
for(int i = x; i > 0; i--)
for(i = y; i > 0; i--)
System.out.print("*");
System.out.println();
} // createBox()
public void getInput() throws IOException
BufferedReader input = new BufferedReader
(new InputStreamReader(System.in));
System.out.print("Enter a number of rows: ");
String inputString = input.readLine();
row = convertStringToInteger(inputString);
System.out.print("Enter a number of columns: ");
inputString = input.readLine();
col = convertStringToInteger(inputString);
} // getInput()
/****Helper()****/
private int convertStringToInteger(String s)
Integer intObject = Integer.valueOf(s);
return intObject.intValue();
} // convertStringToInt()
} // AsteriskBox class
import java.io.*;
public class AsteriskBoxUser
public static void main(String args[]) throws IOException
AsteriskBox box = new AsteriskBox();
System.out.println("This program creates a box made of asterisks with values given by you!");
System.out.println();
box.getInput();
box.createBox(AsteriskBox.row, AsteriskBox.col);
}You will never break out of the first loop because you are using the same index variable i for both of your nested loops. Use a different variable, say j for your inner loop.
Incidentally, your row and col variables are mislabeled. If you use the static modifier, they are class variables, not instance variables. This could cost you points on your assignment since it would imply that you don't know the difference. -
I'm currently making a table similar to the Product Table on
the Spry demo. I'm having some problems because I need to link
videos and sounds from nested XML categories to a sidebar, similar
to the features list on the demo site. The problem is, I dont want
the full URL to show, but something else
I managed to get the list to show what I wanted by doing
something like this:
<media>
<video>2004/videos/x.mov <name>Great Video
</name> </video>
</media>
By calling spry:region="media" and then
<ul><li><a
href={video}>{name}</a><li></ul>
I got a full list with the names, but the links were
apparently lost, and all pointed to the table's url.
I also tried doing a <div spry:region="media"
spry:region="name"> and list the <video> and <name>
tags separately on the XML, but that didn't work.
I'd be very greatful if someone could help me figure out how
to do this.
Thank you,
JoseJust looking at your post, I noticed that when you put the ibar in your shelf and add applications the icons don't like to show up you have to
1. right click on the application in the ibar
2. select icon program-properties-icon
3.click on the grey box
4.navigate to /usr/share/icons/highcoler/64x64/apps (you can select 48x48 as well)
The icon should show up in ibar, as well as the applcation menu. It is hit and miss though. I hope this helps.
Edit: I think I solved the hit and miss attribute, instead of selecting the file in the middle of the window manager select it to the right. And make sure that the file shows up in the bar at the bottom of the filemanager window.
Last edited by mich04 (2012-11-25 13:40:36) -
Hello -
HELP!!!!! I need to join the following tables so I can compare the totals of colVal1+colVal2+colVal3 in tblIMP with ColTOTAL_NVal in AnotherDB.dbo.BL
Below are the important columns along with relationships from the tables. Is this even possible?
tblIMP
PK IMP integer
TNum
colVal1
colVal2
colVal3
colVal4
tblSC
PK IntCNum numeric(7,)
FK ISN numeric(8,0)
TNum
tblSD
PK IntSLNum numeric(7,0)
FK ISN
tblSH
PK ISN numeric(8,0)
Sh_ID nvarchar(25)
AnotherDB.dbo.BL
PK BL_ID integer
Sh_ID nvarchar(100)
ColTOTAL_NVal
TNum in tblIMP has duplicates (not for the row, but for TNum itself)
TNum in tblSC has duplicates also (not for the row, but for TNum itself)
tblSH has a one-to-many relationship with tblSC;
tblSH has a one-to-many relationship with tblSD;
tblSD has a one-to-many relationship with tblSC
tblSC is a recursive table – think container with many TNum in it
ANY HELP AT ALL WILL BE APPRECIATED!!!
JuniormintThanks for your response, Latheesh.
I would have posted the DDL, sample data and desired output, but I'm on a contract job and am unable to divulge that information. Is there anything that is not understandable with what I have posted? If so, please let me know.
Juniormint
You need to atleast explain us with some INDICATIVE data how your tables hold information and how you want the output to appear. Otherwise its hard for us by just looking at some table structure alone as we cant see your system neither knows your rules.
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
Help with multiple table joins
I'm trying to limit the results of a query joining multiple tables. I have a main table, tbl_webrequests, and multiple tables with supporting information. The unique column for tbl_webrequests is reqID. There is another table, tbl_instructions, that holds all the instructions tied to each request. I join the tables using reqID.
I'm trying to construct a page that has all of the records in tbl_webrequests. The problem I'm having is that with each request that has multiple instructions, I have multiple results because of the multiple instructions for one reqID. For now, all I want is the original instruction to display. Below is the original query, and below that is what I'm trying to get the query to do for each record in tbl_webrequest. Note that 319 is a random uniqueID in tbl_webrequests.
SELECT
DISTINCT W.reqID, W.dt_close, W.dt_due, W.subject, W.statusid, W.empID, W.priorityid, W.assigneeid, W.categoryid, W.url, W.hrs,
W.closingNotes, W.mins, W.requestTypeID, I.instructions, I.instID
from tbl_webrequests W left join
(select reqID, instID, instructions from tbl_instructions) I on W.reqID = I.reqID
ORDER BY I.instID asc;
SELECT
distinct I.instructions, I.instID, W.reqID, W.dt_close, W.dt_due, W.subject, W.statusid, W.empID, W.priorityid, W.assigneeid, W.categoryid, W.url, W.hrs,
W.closingNotes, W.mins, W.requestTypeID
from tbl_webrequests W left join
(select reqID, instID, instructions from tbl_instructions where rowNum = 1 and reqid = 319 order by instID asc) I on W.reqID = I.reqID
where W.reqID = 319
ORDER BY I.instID asc;
My question is, how do I pass the reqID as a variable into the join subquery so that the query returns only returns the first joined item in tbl_instructions for each record in tbl_webrequests?
Any help is appreciated
Thanks!Scrap the "DISTINCT" and try something like this:
Select
I.Instructions, I.Instid
, W.Reqid, W.Dt_Close, W.Dt_Due, W.Subject, W.Statusid, W.Empid, W.Priorityid
, W.Assigneeid, W.Categoryid, W.Url, W.Hrs, W.Closingnotes, W.Mins, W.Requesttypeid
From Tbl_Webrequests W Left Join
( Select Reqid, Instid, Instructions
From Tbl_Instructions I0
Where Instid = (Select Min(Instid) From Tbl_Instructions I1
Where I1.Reqid = I0.Reqid)
) I On W.Reqid = I.Reqid
Where W.Reqid = 319
Order By I.Instid Asc;;) -
Help with exercise on joins and group by
Could someone help me with an exercise I'm working on? This isn't "homework", per se, as it's not an assignment, I'm just doing my own personal research.
I have the usual tables "DEPARTMENT" and "EMPLOYEE", with the following columns:
Department:
* NAME
* ID
Employee:
* SSN
* NAME
* DEPT_ID
* SALARY
I'm able to build a query that summarizes the departments with total employee salary > 30000, like this:
select dept_id, sum(salary) from employee group by dept_id having sum(salary) > 30000;
What I'd like to extend this to is a summary of departments with total employee salary > 30000 OR no employees at all (or total salary = 0, conceptually).
I imagine this will include a left outer join, but I can't get this to work.http://download.oracle.com/docs/cd/B19306_01/server.102/b14223/aggreg.htm#sthref1670
http://www.oracle.com/technology/products/oracle9i/daily/oct10.html
http://www.dba-oracle.com/t_sql99_with_clause.htm
http://www.psoug.org/reference/with.html
WITH clause is used for reusability of sub queries within a query. And in this case it is useful to build the query without having to create a table with data and show the results.
SQL> select 1 dept_id, 'ABC' dept_name from dual;
DEPT_ID DEP
1 ABCHere I am selecting some static values from dual table where I say I want 1 as dept_id and its name as ABC.
SQL> select 1 dept_id, 'ABC' dept_name from dual union all
2 select 2 dept_id, 'XYZ' dept_name from dual union all
3 select 3 dept_id, 'MNO' dept_name from dual;
DEPT_ID DEP
1 ABC
2 XYZ
3 MNOIn the above query I am selecting 3 static department ids and names in three separate queries and combining them using union all. Thus I am getting them as three rows.
SQL> with dept as(
2 select 1 dept_id, 'ABC' dept_name from dual union all
3 select 2 dept_id, 'XYZ' dept_name from dual union all
4 select 3 dept_id, 'MNO' dept_name from dual )
5 --
6 select * from dept;
DEPT_ID DEP
1 ABC
2 XYZ
3 MNOHere, In the above query, I just named the previous query as "dept" and I am just selecting all from "dept". You can say it something like a virtual table which has data based on a query, that can be reused in other/main query. The limitations, uses and elaborate descriptions are available in the links I provided. -
Help with posting a "join us" page
I have made a “join us” page for our site, but
was unhappy with what I finished with. We want people to send us
their information so that they can be updated on special offers.
But, when the person fills out the form and then clicks on send,
he/she is then warned about sending their e-mail addresses. If they
"ok" that, they are then warned about a virus possibilities and do
they still want to send it. If it was me, I would say no. I want to
make this so that the information that the person filled out is
sent straight to me. On all other sites that I’ve joined
there is no warning or anything else. What do I need to do to fix
this so that the person filling out the form does not have to
answer everything at the end? This is the address to the site:
http://www.idermed.com/sign_up.asp
One last thing, I am new at making full internet sites with
DreamWeaver. In designing and making them, no problem, but when it
comes down to the codes and what .asp addresses need to be where, I
am brand new. So please try and help me using "english".
Thank Youthe problem is that you are using a mailto in the form
action. It is best to do these types of forms using some type of
server side scripting such as ASP, PHP, JSP etc. to submit the info
to a database behind the scenes.
By having your form action as a mailto, you are relying on
the fact that a person has an email client on their current
computer which is not always the case. -
Hi,
Below are the details of what I am attempting to do.
DB version: 10.2.0.4.0
Sample Table Definition
create table t_cnf
conf_id number,
conf_value number,
conf_cat_id number,
actv_flg char(1)
create table t_int_act
int_acc_id number,
frst_mrch_id number,
create_date date
create table t_int_act_cast
int_acc_id number,
cast_id number
create t_cast_alt_nmnt
cas_alt_nmt_id number,
cas_alt_id number,
cast_id number,
enrl_flg char(1),
src_id number
);Sample Data
insert into t_cnf values (1, 78965098, 12, 'Y');
insert into t_cnf values (1, 78965098, 13, 'Y');
insert into t_int_act values (234,78965098, trunc(sysdate) - 1);
insert into t_int_act_cast values (234, 560432);
insert into t_cas_alt_nmnt values (1, 2, 560432, 'Y', 2); Need to fetch all cast_ids that are not in t_cast_alt_nmnt or cast_ids that are present in t_cast_alt_nmnt but have t_cast_alt_nmnt.enrl_flg = 'N' and t_cast_alt_nmnt.cast_alt_id in (2,3) and t_cast_alt_nmnt.src_id <> 2
for t_int_act.frst_mrch_ids matching t_cnf.conf_vale
Records fetch will insert a record into t_cast_alt_nmnt with css_alt_id 2 or 3 (determined by pe_or_pd).
I attempted to write below sql. This works fine when cast_id does not exists in t_cast_alt_nmnt but will not return correct results when there is a record in t_cast_alt_nmnt matching above criteria.
select
iac.cast_id cast_id,
sysdate upd_date,
case
when c.conf_cat_id = 12 then 2
when c.conf_cat_id = 13 then 3
end
pe_or_pd
from
t_cnf c
join
t_int_act ia
on
ia.frst_mrch_id = c.conf_value
join
t_int_act_cast iac
on
ia.int_acc_id = iac.int_acc_id
left join
t_cast_alt_nmnt can
on
can.cast_id = iac.cast_id and
can.enrl_flg = 'N' and
can.cas_alt_id in (2,3) and
can.src_id <> 2
where
c.conf_cat_id in (12,13) and
c.actv_flg = 'Y' and
-- Fetch all new customer created day before.
ia.create_date >= trunc(sysdate) - 1
Expected results
With no cast_id record in t_cast_alt_nmnt
cast_id upd_date pe_or_pd
560432 4/19/2012 2
560432 4/19/2012 3
With cast_id record in t_css_alt_nmt (insert provided)
cast_id upd_date pe_or_pd
560432 4/19/2012 3
Appreciate your help
Edited by: user572194 on Apr 19, 2012 1:04 PMThanks Frank for taking time to look into this and providing sql. I will test is against use cases (mentioned below).
And I apologize for the typos. I had to change table and column names as it is policy of our company not to post data model details in public forums.
Requirement:
1. New cast ids will be added daily and these will get inserted into t_int_act and t_int_act_cas
2. t_cnf has 2 conf_cat_id configured 12 and 13 and each conf_cat_id will have same conf_values (same as t_int_act.frst_mrch_id) but actv_flg might be different (set to N for 12 and Y for 13). Need to fetch only active ones
3. t_cas_alt_nmnt will have cast_ids that are enrolled to receive certain mails if enrl_flg is Y for these. Not all cast_ids will have record in this table.
When a cast_id is enrolled by customer service, a record will get inserted with src_id = 2.
4. Requirement is to enroll new cast_ids created with frst_mrch_id matching t_cnf.conf_value where conf_cat_id in (12,13)
Match criteira:
If t_int_act_cas.cast_id exists in t_cas_alt_nmnt and have enrl_flg = 'Y' for cas_alt_id = 2 then
insert record with same cast_id, enrl_flg = 'Y' and css_alt_id = 3
If t_int_act_cas.cast_id exists in t_cas_alt_nmnt and have enrl_flg = 'Y' for cas_alt_id = 3 then
insert record with same cast_id, enrl_flg = 'Y' and css_alt_id = 2
If t_int_act_cas.cast_id exists in t_cas_alt_nmnt and have enrl_flg = 'N' for cas_alt_id in (2,3) and src_id = 2 then
Ignore this record.
if t_int_act_cas.cast_id not exists in t_cas_alt_nmnt then
insert 1 record each with cast_id, enrl_flg = 'Y' for css_alt_id 2 and 3
Hope above explanation makes sense.
By the way I tried below sql. Yet to test it for all use cases but it worked for the last two.
Note on PE_OR_PD column. I am just using this column to write separate inserts for css_alt_id 2 and 3.
select
cast_id,
upd_date,
pe_or_pd
from
(select
iac.cast_id cast_id,
sysdate upd_date,
case
when c.conf_cat_id = 12 and can.cas_alt_id in (2,3) and enrl_flg = 'Y' then null
when c.conf_cat_id = 13 and can.cas_alt_id in (2,3) and enrl_flg = 'Y' then null
when c.conf_cat_id = 12 and nvl(can.cas_alt_id,2) = 2 and nvl(can.enrl_flg,'Y') = 'N' and can.src_id <> 2 then 'PE'
when c.conf_cat_id = 13 and nvl(can.cas_alt_id,3) = 3 and nvl(can.enrl_flg,'Y') = 'N' and can.src_id <> 2 then 'PD'
when c.conf_cat_id = 12 and nvl(can.cas_alt_id,2) = 2 and nvl(can.enrl_flg,'Y') = 'Y' then 'PE'
when c.conf_cat_id = 13 and nvl(can.cas_alt_id,3) = 3 and nvl(can.enrl_flg,'Y') = 'Y' then 'PD'
end
pe_or_pd
from
t_cnf c,
t_int_act ia,
t_intl_act_cus iac,
t_cas_alt_nmnt can
where
c.conf_value = ia.frst_mrch_id and
ia.internal_account_id = iac.int_act_id and
can.cast_id(+) = iac.cast_id and
c.conf_cat_id in (12,13) and
c.actv_flg = 'Y' and
-- Fetch all new customer created after last run.
ia.create_date >= trunc(sysdate) - 1
) enrl_cust
where
pe_or_pd is not null
; -
Hi,
I Have this database structure:
Artist(IDA,Name,Year_b)
Work(IDW,Title,IDA,IDL)
City(IDL,IName,Nation)
I Want to do a query that retrieve for one Artist all Works availables on database and,if present,the City where each work was realized.
This SQL code is correct?
SELECT Name,Title,IName
FROM Artist a,
Work w LEFT OUTER JOIN City c ON w.IDL=c.IDL
WHERE w.IDA=a.IDA and a.IDA='2';
If it's not correct, what type of correction need it?
Thanks for Help
AndreaIf you asked... The original query works, but it is not "right".
You should use either the old Oracle style of joins, like in the VM's query, or, better, the ANSI join style, recommended by Oracle (not a mix of them, like in your query):
SELECT a.name,
w.title,
c.iname
FROM artist a
JOIN work w
ON w.ida = a.ida
LEFT OUTER JOIN city c
ON w.idl = c.idl
WHERE a.ida = '2' -
I can't figure out how to combine a full outer join with another type of join ... is this possible?
Here's some create table and insert statements for some basic sample data:
CREATE TABLE my_tab1
( record_id NUMBER NOT NULL
, workstation VARCHAR2(4)
, my_value NUMBER
CONSTRAINT my_tab1_pk PRIMARY KEY (record_id)
INSERT INTO my_tab1
VALUES(1,'ABCD',10);
INSERT INTO my_tab1
VALUES(2,'ABCD',15);
INSERT INTO my_tab1
VALUES(3,'ABCD',5);
INSERT INTO my_tab1
VALUES(4,'A123',5);
INSERT INTO my_tab1
VALUES(5,'A123',10);
INSERT INTO my_tab1
VALUES(6,'A123',20);
INSERT INTO my_tab1
VALUES(7,'????',5);
CREATE TABLE my_tab2
( workstation VARCHAR2(4)
, wkstn_name VARCHAR2(20)
CONSTRAINT my_tab2_pk PRIMARY KEY (workstation)
INSERT INTO my_tab2
VALUES('ABCD','WKSTN 1');
INSERT INTO my_tab2
VALUES('A123','WKSTN 2');
INSERT INTO my_tab2
VALUES('B456','WKSTN 3');
CREATE TABLE my_tab3
( my_nbr1 NUMBER
, my_nbr2 NUMBER
INSERT INTO my_tab3
VALUES(1,2);
INSERT INTO my_tab3
VALUES(2,3);
INSERT INTO my_tab3
VALUES(3,4);And, the results I want to get:
workstation sum(my_value) wkstn_name my_nbr1 my_nbr2
ABCD 30 WKSTN 1 1 2
ABCD 30 WKSTN 1 2 3
ABCD 30 WKSTN 1 3 4
A123 35 WKSTN 2 1 2
A123 35 WKSTN 2 2 3
A123 35 WKSTN 2 3 4
B456 0 WKSTN 3 1 2
B456 0 WKSTN 3 2 3
B456 0 WKSTN 3 3 4
???? 5 NULL 1 2
???? 5 NULL 2 3
???? 5 NULL 3 4I've tried a number of different things, googled my problem, and no luck yet...
SELECT t1.workstation
, SUM(t1.my_value)
, t2.wkstn_name
, t3.my_nbr1
, t3.my_nbr2
FROM my_tab1 t1
, my_tab2 t2
, my_tab3 t3
...So, what I want is a full outer join of t1 and t2 on workstation, and a cross-join of that with t3. I'm wondering if I can't find any examples of this online because it's not possible....
Note: I'm stuck dealing with Oracle 8i
Thanks!!Hi,
The query I posted yesterday is a little more complicated than it needs to be.
Since my_tab2.workstation is unique, there's no reason to do a separate sub-query like mt1; we can join my_tab1 to my_tab2 and get the SUM all in one sub-query.
SELECT foj.workstation
, foj.sum_my_value
, foj.wkstn_name
, mt3.my_nbr1
, mt3.my_nbr2
FROM ( -- Begin in-line view foj for full outer join
SELECT mt1.workstation
, SUM (mt1.my_value) AS sum_my_value
, mt2.wkstn_name
FROM my_tab1 mt1
, my_tab2 mt2
WHERE mt1.workstation = mt2.workstation (+)
GROUP BY mt1.workstation
, mt2.wkstn_name
UNION ALL
SELECT workstation
, 0 AS sum_my_value
, wkstn_name
FROM my_tab2
WHERE workstation NOT IN ( -- Begin NOT IN sub-query
SELECT workstation
FROM my_tab1
WHERE workstation IS NOT NULL
) -- End NOT IN sub-query
) foj -- End in-line view foj for full outer join
, my_tab3 mt3
ORDER BY foj.wkstn_name
, foj.workstation
, mt3.my_nbr1
, mt3.my_nbr2
;Thanks for posting the CREATE TABLE and INSERT statements, as well as the very clear desired results!
user11033437 wrote:
... So, what I want is a full outer join of t1 and t2 on workstation, and a cross-join of that with t3. That it, exactly!
The tricky part is how and when to get SUM (my_value). You might approach this by figuring out exactly what my_tab3 has to be cross-joined to; that is, exactly what should the result set of the full outer join between my_tab1 and my_tab2 look like. To do that, take your desired results, remove the columns that do not come from the full outer join, and remove the duplicate rows. You'll get:
workstation sum(my_value) wkstn_name
ABCD 30 WKSTN 1
A123 35 WKSTN 2
B456 0 WKSTN 3
???? 5 NULL So the core of the problem is how to get these results from my_tab1 and my_tab2, which is done in sub-query foj above.
I tried to use self-documenting names in my code. I hope you can understand it.
I could spend hours explaining different parts of this query in more detail, but I'm sure I'd waste some of that time explaining things you already understand. If you want an explanation of somthing(s) specific, let me know. -
Help with query - inner join and case
Hi this is the query I am having troble with, where is the correct place to add the case condition:
SELECT
FROM
END_USER_ORDERS EO
INNER JOIN ORDER_PRODUCTS OP
ON EO.EUO_ID = OP.EUO_ID
INNER JOIN PRODUCTS P
ON OP.PRD_ID = P.PRD_ID
CASE P.PRD_ID -- PROBLEM IS HERE
WHEN 'Online' Then 'Public'
END
INNER JOIN PRODUCT_VERSIONS PV
ON P.PRD_ID = PV.PRD_ID
AND PV.SIT_ID = 'DEFAULT'
AND PV.LOC_ID = 'UK'
LEFT OUTER JOIN ORDER_SESSIONS OS
ON OP.EUO_ID = OS.EUO_ID
AND OP.ORP_SEQ_NO = OS.ORP_SEQ_NO
LEFT OUTER JOIN SESSIONS S
ON OS.SES_ID = S.SES_ID
LEFT OUTER JOIN SUBJECTS SU
ON S.SUB_ID = SU.SUB_ID
WHERE EO.EUO_ID = 'bef8cd51-b398-4521-9350-f3a7c3885c59'
select * from END_USER_ORDERS
order by EUO_DATE desc
Many thankshmmm....one more point here, when you change your query use as below:
SELECT
Col1,Col2.... -- specify your columns
,CASE P.PRD_TYPE
WHEN 'Online' Then 'Public'
else P.PRD_TYPE -- to display others as original value
END AS [PRODUCT TYPE]
FROM
END_USER_ORDERS EO -
basically i need to make a diamond shape out of asterisks. There should be 11 in the middle and decreasing by 2 each line above and below it, until it reaches 1. Now i've come up with a for loop that prints what i need for the top half of the diamond(but the asterisks are not centered). How would i center them and also print the bottom half of the diamond? here's what i have so far.
import java.io.*;
class diamond{
public static void main(String[] args)
int a;
int b;
for(a = 1; a <=11; a++)
for(b = 1; b <= a; b++)
System.out.print('*');
System.out.println();
}here's what it outputs:
Press any key to continue . . .public class Diamond {
private static final int MAX = 11;
private static final int MIN = 1;
public static void main(String[] args) throws Exception {
for(int a = MIN; a <= MAX; a++) {
for(int b = MAX; b >= MIN; b--) {
if(b <= a) {
System.out.print(" *");
} else {
System.out.print(" ");
System.out.println();
for(int a = MIN; a <= MAX; a++) {
for(int b = MIN; b <= MAX; b++) {
if(b <= a) {
System.out.print(" ");
} else {
System.out.print(" *");
System.out.println();
}And here's my output:
*
Maybe you are looking for
-
How do I buy a song from the UK store if I use the United States store?
I use the United States store and I noticed that one of my favorite bands, Busted, has some songs I want but they are in the UK store. I tried to buy them but it said I couldn't. Is there anyway to get these songs?
-
Can't able to edit the query in query designner
Hello every one, Please help me in below issue. It is really important. Actually i have create the query in the BI- Development and that i pass to the production. Now. I tried to again edit the same query in the development , a
-
How to arrange days in coloumn wise in crosstab
Dear all, I have a report which counts number of days and number of jobs with their percentages. Now number of days are shown like this Day --- Jobs --- Percentage 1 --- 23 --- 2% 2 --- 45 3 --- 56 4 --- 78 5 --- 100 The above is for
-
TS3989 Question on iPhone photo stream.
I just enabled Photo Stream on my iPhone. There are 230 pictures in my camera roll. I do not see any of these pictures in "My Photo Stream". It appears that only the new pictures going forward will be added. Is that correct? I would like to add
-
Hi, I am using the below code snippet to render my pages based on certain conditions <h:form> <ui:fragment rendered="#{mybean.pageName eq 'CourseType'}"> <ui:include src="/pages/courseTypePage.xhtml /> <ui:fragment> <ui:fragment rendered="#{mybean.pa