I should get multiple values from 2 connected table. I will pass the filtered value to the output table.
Table A:
ID=001
Category='ANIMAL'
Table B:
ID=B001
FAMILY NAME
'ANIMAL' 'DOG'
'ANIMAL' 'CAT'
'ANIMAL' 'PIG'
I have used TOracleInput and TOracleOutput. and Im only getting PIG on my Output Table.....
How should I do it to pass Dog, Cat and Pig on my output table?
Thank You in Advance.
.so your structure should be tOracleInput1-->tmap(another tOracleInput2 used as lookup to this) and then in tMap take output and move that output to tOracleOutput
problem is how you are joining the two inputs in tmap. You should be doing something like tinput1.column_id joined to toracleinput2.column_id and in properties for join select match model as ALL Matches, join model Inner join or Left ouer join based on your need.
Related
I have two tables:
The merge is on the field name value of the JLE_LineTypeCategory matching the Type and Line Type columns on JobLedgerEntry. In SQL, I would do something like this:
SELECT optiontext
FROM metadataTable md
WHERE TableName='JobLedgerEntry'
AND FieldName='LineType'
AND md.OptionInteger=JobLedgerEntry.[Type]
) as 'Type'
but I'm not sure how to do that in BI. Basically, I'm looking at the value of a field in the JLE_LineTypeCategory table to match with the column name in the JobLedgerEntry table.
Since I only needed one set of field descriptors, I filtered the LineTypeCategory table to just the 3 possible values for the JobLedgerEntry.LineType field. I then merged the two tables on the optionInteger-LineType fields.
I am quite new in working with psql.
Goal is to get values from a nested jsonb-structure where the last key has so many different characteristics it is not possible to query them explicitely.
The jsonb-structure in any row is as follows:
TABLE_Products
{'products':[{'product1':['TYPE'], 'product2':['TYPE2','TYPE3'], 'productN':['TYPE_N']}]}
I want to get the values (TYPE1, etc.) assigned to each product-key (product1, etc.). The product-keys are the unknown, because of too many different names.
My work so far achieves to pull out a tuple for each key:value-pair on the last level. To illustrate this here you can see my code and the results from the previously described structure.
My Code:
select url, jsonb_each(pro)
from (
select id , jsonb_array_elements(data #> '{products}') as pro
from TABLE_Products
where data is not null
) z
My result:
("product2","[""TYPE2""]")
("product2","[""TYPE3""]")
My questions:
Is there a way to split this tuple on two columns?
Or how can I query the values kind of 'unsupervised', so without knowing the exact names of 'product1 ... n'
I have created a JSON type variable that looks like so, named group.
'{"SG1": ["2", "4"], "SG2": ["6", "8", "10"], "SG3": ["9"]}'
The idea is to create multiple values for a single key for example PF1 is a group (key) that has a list of values.
I want to create a table for such JSON variable that can give me output like,
group
values
PF1
2,4
PF2
6,8,10
PF3
9
The value column can be a string or comma-separated integer values, string is preferred.
I have tried
SELECT group ->> 'PF1' as group_1
from metadata;
Ths gives me a blank cell.
I am working with JSON in PostgreSQL for the first time so I have no idea about functions that might help me achieve this. Any help is appreciated.
It's not clear to me, what you are trying to achieve, but it seems you want each key/value pair as a row in the output:
select t.*
from metadata m
cross join jsonb_each_text(m."group") as t("group", values)
Online example
If your group column isn't jsonb but json you need to use json_each_text()
Note that group is reserved keyword and needs to be quoted every time you use it. It would be easier if you found a different name.
i got two tables in a master-detail relation and want to select all data in a single select query.
table "person":
id;name
1;Allen
2;Bert
3;Chris
table "connectivity":
id;personId;type;value
1;1;phone;+123456789
2;1;mail;allen#allen.allen
3;2;mail;bert#bert.bert
4;3;phone;+987654321
5;3;fax;+987654322
The query output should be something like
person.id;person.name;phone;mail;fax
1;Allen;+123456789;allen#allen.allen;
2;Bert;;bert#bert.com;
3;Chris;+987654321;;+987654322
Any idea possibly without writing some function?
It should dynamically add the colummns when the detail-table is extended. E.g. adding a row to the detail table like
6;2;icq;0123456789
My prefered solution would fit into a select-query.
Thanks!
Patrick
It is not possible to add columns to a static SQL query.
The model you are using is called "Entity–attribute–value model". You can google for details on its different implementations.
The only "easy" way (I can think of) to have many dynamic properties per object in SQL is to dump them all into a single structure like HSTORE, JSON(B), BLOB... In this case the output will loke like:
id;name;params
1;Allen;{"phone":"+123456789", "email":"allen#allen.allen"};
2;Bert;{"email":"bert#bert.com"};
3;Chris;{"phone":"+987654321", "fax":"+987654322"};
You need a JOIN and a CASE to select the values you need. Something like this:
SELECT person.id,
person.name,
CASE connectivity.type WHEN 'phone' THEN value END AS phone,
CASE connectivity.type WHEN 'mail' THEN value END AS mail,
CASE connectivity.type WHEN 'fax' THEN value END AS fax
FROM person
JOIN connectivity ON person.id = connectivity.personId;
Offtopic: Don't use a mix of UPPER and lower case, PostgreSQL only uses lower case unless you put everything between "double quotes".
select
p.name,
phone.value phone,
mail.value mail
from person p
left join connectivity phone on phone.personid = p.id and phone.type = 'phone'
left join connectivity mail on mail.personid = p.id and mail.type = 'mail'
I'm having trouble with the 'Ambiguous column name' issue in Transact-SQL, using the Microsoft SQL 2012 Server Management Studio.
I´ve been looking through some of the answers already posted on Stackoverflow, but they don´t seem to work for me, and parts of it I simply don´t understand or loses the general view of.
Executing the following script :
USE CDD
SELECT Artist, Album_title, track_title, track_number, Release_Year, EAN_code
FROM Artists AS a INNER JOIN CD_Albumtitles AS c
ON a.artist_id = c.artist_id
INNER JOIN Track_lists AS t
ON c.title_id = t.title_id
WHERE track_title = 'bohemian rhapsody'
triggers the following error message :
Msg 209, Level 16, State 1, Line 3
Ambiguous column name 'EAN_code'.
Not that this is a CD database with artists names, album titles and track lists. Both the tables 'CD_Albumtitles' and 'Track_lists' have a column, with identical EAN codes. The EAN code is an important internationel code used to uniquely identify CD albums, which is why I would like to keep using it.
You need to put the alias in front of all the columns in your select list and your where clause. You're getting that error because one of the columns you have currently is coming from multiple tables in your join. If you alias the columns, it will essentially pick one or the other of the tables.
SELECT a.Artist,c.Album_title,t.track_title,t.track_number,c.Release_Year,t.EAN_code
FROM Artists AS a INNER JOIN CD_Albumtitles AS c
ON a.artist_id = c.artist_id
INNER JOIN Track_lists AS t
ON c.title_id = t.title_id
WHERE t.track_title = 'bohemian rhapsody'
so choose one of the source tables, prefixing the field with the alias (or table name)
SELECT Artist,Album_title,track_title,track_number,Release_Year,
c.EAN_code -- or t.EAN_code, which should retrieve the same value
By the way, try to prefix all the fields (in the select, the join, the group by, etc.), it's easier for maintenance.