I have this query which returns active users for our EBS system. Im trying to join this results with one more table in order to get theirs supervisor id but my problem is that i get cartesian product when trying to join with email address column of table EMPDATA_IMPORT. I need to use email column, because i do not have employee id populated for some users in fnd_user table.
SELECT
fu.user_name "User name", frt.responsibility_name "Responsibility Name" ,
furg.start_date "Start Date" , furg.end_date "End Date" ,
fu.last_logon_date "Last Logon Date", fr.responsibility_key "Responsibility key",
fu.email_address "Email Address", fu.description "Description", x.supervisor_id
FROM
fnd_user_resp_groups_direct furg, fnd_user fu,
applsys.fnd_responsibility_tl frt, applsys.fnd_responsibility fr, EMPDATA_IMPORT x
WHERE furg.user_id = fu.user_id
AND furg.responsibility_id = frt.responsibility_id
AND fr.responsibility_id = frt.responsibility_id
AND (to_char(fu.END_DATE) is null OR fu.END_DATE > sysdate)
and fu.email_address=x.EMAIL_ADDRESS -- x has non distinct values for email address
Ok i will try to describe table data for EMPDATA_IMPORT :
Emp_id Full_name supervisor_id email_address
10 John Doe 100 jdoe#mm.com
10 John Doe 100 jdoe#mm.com
10 John Doe 100 jdoe#mm.com
100 Mike King 200 mking#mm.com
One other thing, by joining with email column above one i need to somehow present manager's name (using supervisor id) in above query. I cant figure it out....
How to manage this?
Thanks
I dont know how to get all the contact information that is stored in HZ_PARTIES.
We have HZ_PARTIES AND HZ_PARTY_SITES, both have contact information, right?.
I want to obtain the information from HZ_PARTIES.
The problem is that my query is not working properly, it does not retrieve the information that i want. If i use this query:
SELECT
hp.party_name
, hca.account_number
, hcp.phone_number
, hcp.email_address
FROM apps.hz_cust_accounts hca
INNER JOIN apps.hz_cust_acct_sites_all hcas ON hca.cust_account_id = hcas.cust_account_id
INNER JOIN apps.hz_party_site hps ON hcas.party_site_id = hps.party_site_id
INNER JOIN apps.hz_locations hl ON hps.location_id = hl.location_id
INNER JOIN apps.hz_parties hp ON hps.party_id = hp.party_id
LEFT JOIN (
SELECT
owner_table_id
, max(case when contact_point_type = 'PHONE' then phone_number end) phone_number
, max(case when contact_point_type = 'EMAIL' then email_address end) email_address
FROM hz_contact_points
WHERE status = 'A'
AND primary_flag = 'Y'
AND owner_table_name = 'HZ_PARTIES'
AND contact_point_type IN ('EMAIL','PHONE')
GROUP BY
owner_table_id
) hcp ON hcas.party_site_id = hcp.owner_table_id
WHERE hcas.status = 'A'
AND hps.status = 'A'
AND hca.status = 'A'
--AND hca.account_number = 'account_number'
;
DO NOTE that i am using this condition:
hcp ON hcas.party_site_id = hcp.owner_table_id
But this query IS NOT working properly because if i want to find all the contact information for a specific account number, it should return an email but instead it returns NULL
The fact is if i put this another condition in exchange for the previous one:
hcp ON hcas.party_site_id = hps.party_site_id
It returns several results for a single account_number, everything is wrong BUT it DOES show the email that i am looking for.
What is going on here?
Could you please help me to solve this?
PS: Everytime that a customers is created, this PROCEDURE is executed:
https://www.codepile.net/pile/9nzMKy4D
As I know HZ_PARTIES = HZ_PARTY_SITES this is one to many relation. So HZ_PARTY_SITES can contain e.g. address "bill to", "ship to" etc.
First of all, check in EBS how many sites the customer has.
I also recommend you page http://etrm.oracle.com/pls/etrm/etrm_search.search. You can check the relation between the EBS's tables there.
enter image description here
As you can see, the relation between hcp ON hcas.party_site_id = hcp.owner_table_id
not exists.
Here is my table structure
table1 - PLAYER
PlayerID
FirstName
LastName
EmailAddress
CellNo
Table2 - Team
TeamID
TeamName
Table3 - TEAMPLAYERS
ID
PlayerID
TeamID
A player can be part of more than one team.
Question:
Now I want to get the player basic details along with the count of no. of teams he plays for. I use the following query to get the result in SQL:
SELECT P.FirstName, P.LastName, P.EmailAddress, P.CellNo, COUNT(TP.TeamID)
FROM Player P
JOIN TeamPlayer TP ON P.PlayerID = TP.PlayerID
GROUP BY P.PlayerID, P.FirstName, P.Lastname, P.EmailAddress, P.CellNo;
This works perfectly.
However, im stuck when converting this to linq. Not much of help from online resources. Can someone help me with this?
Database Contexts dbContext.Players and dbContext.TeamPlayers are just representational, check your project for right context
var result= (from player in dbContext.Players
join teamPlayer in dbContext.TeamPlayers
on player.PlayerID equals teamPlayer.PlayerID
select new{player,teamPlayer})
.GroupBy(P=>new
{
P.PlayerID,
P.FirstName,
P.Lastname,
P.EmailAddress,
P.CellNo
})
.Select(x=>new
{
x.Key.FirstName,
x.Key.LastName,
x.Key.EmailAddress,
x.Key.CellNo,
TeamIDCount=x.Count(z=>z.teamPlayer.TeamID)
}).ToList();
I have datetime data in my input and would like to load it correctly from Pig. I googled and learned it's suggested to load as chararray then covert to datetime with ToDate function. However, sometimes my datetime fields are NULL. Then, I'm getting NULL Pointer Exception from PIG when I try to apply the ToDate Function. I am trying to use bincond operator but I'm getting the following error:
mismatched input '?' expecting SEMI_COLON
Which does not make sense.
=====================================================================
Here is the code that I have so far:
transactions_edited = FOREACH transactions GENERATE
id,
code,
user_id,
visit_code,
channel_id,
transaction_type,
product_category,
product_subcategory,
specific_id,
specific_type,
email,
cpf,
name,
last_name,
gender,
birth_date,
phone_code,
phone,
additional_phone_code,
additional_phone,
zip_code,
monthly_income,
status,
opportunity_status,
ToDate(created_at,'yyyy-MM-dd HH:mm:ss') AS created_at,
ToDate(updated_at,'yyyy-MM-dd HH:mm:ss') AS updated_at,
old_status,
old_masked_id,
address_type,
address,
address_number,
address_complement,
neighborhood,
city,
state,
landing_path,
referrer,
source,
source_advertising,
keyword,
ad_id,
ad_name,
ad_network,
ad_placement,
ad_device,
cpf_restriction,
mother_name,
registration_form_closed,
(opportunity_status_updated_at is not NULL ) ?ToDate(opportunity_status_updated_at,'yyyy-MM-dd HH:mm:ss') : AS opportunity_status_updated_at,
potential,
interest,
lead_id,
(integrated_at is not NULL) ? ToDate(integrated_at,'yyyy-MM-dd HH:mm:ss') : AS integrated_at,
starred,
channel_input_type,
rg
;
Any help will be really appreciated.
Thanks !
There is a bit correction in ternary operator. Please use below modified code -
transactions_edited = FOREACH transactions GENERATE
id,
code,
user_id,
visit_code,
channel_id,
transaction_type,
product_category,
product_subcategory,
specific_id,
specific_type,
email,
cpf,
name,
last_name,
gender,
birth_date,
phone_code,
phone,
additional_phone_code,
additional_phone,
zip_code,
monthly_income,
status,
opportunity_status,
ToDate(created_at,'yyyy-MM-dd HH:mm:ss') AS created_at,
ToDate(updated_at,'yyyy-MM-dd HH:mm:ss') AS updated_at,
old_status,
old_masked_id,
address_type,
address,
address_number,
address_complement,
neighborhood,
city,
state,
landing_path,
referrer,
source,
source_advertising,
keyword,
ad_id,
ad_name,
ad_network,
ad_placement,
ad_device,
cpf_restriction,
mother_name,
registration_form_closed,
(opportunity_status_updated_at is not NULL ? ToDate(opportunity_status_updated_at,'yyyy-MM-dd HH:mm:ss') : opportunity_status_updated_at) AS opportunity_status_updated_at,
potential,
interest,
lead_id,
(integrated_at is not NULL ? ToDate(integrated_at,'yyyy-MM-dd HH:mm:ss') : integrated_at) AS integrated_at,
starred,
channel_input_type,
rg
;
I have a Hive table named 'Login'. It contains the following columns :-
UserID | UserName | UserIP | UserCountry | Date
On a particular day (all that logins of that day), I want to find out the UserIDs, which has been accessed from a country (UserCountry) from where the user has never accessed his account from OR the IPs (UserIP) from which the account has never been accessed before.
I would start with an except where I remove prior countries and IPs
select userid, usercountry, userip
from table
where date=xx
except
select userid, usercountry, userip
from table
where date<xx
I think that the best way is the GROUP clause!
You say "has never been accessed before", means COUNT = 1.
To find the IP use only once :
select UserId, UserIP, COUNT(UserIP) FROM Login WHERE Date = yourdate GROUP BY UserIP, UserId HAVING COUNT(UserIP) = 1
To find the country use only once :
select UserId, UserCountry, COUNT(UserCountry) FROM Login WHERE Date = yourdate GROUP BY UserCountry, UserId HAVING COUNT(UserCountry) = 1
Left Outer Join will be able to satisfy your requirement in HIVE.
select t1.userid, t1.usercountry, t1.userip
from table t1
LEFT OUTER JOIN
from table t2
ON (t1.userid=t2.userid)
WHERE t1.date=xx and
t2.data < xx and
(t2.usercountry IS NULL or
t2.userip IS NULL);
Hope this helps...