I want to transform following Column:
Col_openingHours:
1: Mo-Sa: 03:00 - 11:00
| 2: Mo-Sa: 02:00 - 10:00
into:
Col_monday:
1: 03:00 - 11:00 |
2: 02:00 - 10:00
Col_tuesday:
1: 03:00 - 11:00 |
2: 02:00 - 10:00
...
How i can get this in Dataprep?
I also have some values in the col1 like "Mo-Fr". And then de Col_saturday has a different columns as source than the showed example (e.g.: Col_openingHours2).
I tried convert values to Columns, but it seems like the wrong tool.
Then i tried to create new columns like col_monday and wanted to set the values with "If(equal (col-openingHours, "Mo-Sa"), ... ) ..
(For this i splitted the cell [Mo-Sa |split| 03:00 - 11:00])
But that wasnt the right tool, too i think.
would be very happy for helping me :)
The most straightforward way to handle this would be to turn your openingHours column into a quick JSON object, so you'd have something like
{
"1": [{
"Mon": "03:00 - 11:00",
"Tues": "03:00 - 11:00",
"Weds": "03:00 - 11:00"
}],
"2": [{
"Mon": "02:00 - 10:00",
"Tues": "02:00 - 10:00",
"Weds": "02:00 - 10:00"
}]
}
This should be achievable by using text pattern replacements and a bit of regex as needed. Once that's done, you can unnest the data itself into columns as you desire, now with the right splits per value.
Related
PostgreSQL timestamp:
begin= '2018-06-07 08:29:49'
end = '2018-06-10 04:07:57'
QUERY:
select sa.\"end\"::timestamp(0) - sa.begin::timestamp(0)
from tabelle sa;
Output:
2 days 19:38:08
I would like to change this output "days" into "Tage", like:
2 Tage 19:38:08
Most important, when there is month different then it should display months in 'Monate', the same goes for years to 'Jahre'.
i tried to look about dateformat, but i need to change expr format not format like '%Y %m %d ...etc.
i tried this too:
to_char(extract(year from (sa."end"::timestamp - sa.begin::timestamp)),'00')||' Jahre '||to_char(extract(month from (sa."end"::timestamp - sa.begin::timestamp)),'00')||' Monate '||to_char(extract(day from (sa."end"::timestamp - sa.begin::timestamp)),'00')||' Tage '||to_char(extract(hour from (sa."end"::timestamp - sa.begin::timestamp)),'00')||':'||to_char(extract(minute from (sa."end"::timestamp - sa.begin::timestamp)),'00')||':'||to_char(extract(second from (sa."end"::timestamp - sa.begin::timestamp)),'00')
Output:
00 Jahre 00 Monate 02 Tage 19: 38: 08
it doesn't look good, cause month or year shall appear if there is number.
Important, only this 'day' needed to be changed in 'Tage' not setting character UFT8 or other things complete in german language!!!
Please i need your support.
There is some solution but in other way:
select extract(day from (sa.\"end\"::timestamp - sa.begin::timestamp))||' Tage '||
to_char(extract(hour from (sa.\"end\"::timestamp-sa.begin::timestamp)),'00')||':'||
to_char(extract(minute from (sa.\"end\"::timestamp - sa.begin::timestamp)),'00')||':'||
to_char(extract(second from (sa.\"end\"::timestamp - sa.begin::timestamp)),'00')
from tabelle sa
Output:
2 Tage 19: 38: 08
Is there a built in function in PostgreSQL 9.5 version to calculate the appropriate century/millenium?
When I use birth_date::TIMESTAMP from a table, sometimes it prefix 19 and sometimes it prefix 20. Below example
Input:
28JUN80
25APR48
Output:
"1980-06-28 00:00:00"
"2048-04-25 00:00:00"
I also have records in the table with birth_date holding values like "07APR1963" which gets computed appropriately as "1963-04-07 00:00:00".
I need use CASE statement when the length is 7 characters, then prefix with 19 millennium and when its 9 characters, just load it as it is.
https://en.wikipedia.org/wiki/Unix_time Unix epoch is
beginning (00:00:00 1 January 1970)
So if you don't specify the century, but just last YY it will be 20th century from 00:00:00 1 January and 21st century before YY equal 70. If you want it to guess the 20th century either append year as you do, or specify CC, eg:
t=> select
to_timestamp('1JAN70', 'ddmonYY')
, to_timestamp('31DEC69', 'ddmonyy')
, to_timestamp('31DEC69 20', 'ddmonyy cc');
to_timestamp | to_timestamp | to_timestamp
------------------------+------------------------+------------------------
1970-01-01 00:00:00+00 | 2069-12-31 00:00:00+00 | 1969-12-31 00:00:00+00
(1 row)
https://www.postgresql.org/docs/current/static/functions-formatting.html
In conversions from string to timestamp or date, the CC (century)
field is ignored if there is a YYY, YYYY or Y,YYY field. If CC is used
with YY or Y then the year is computed as the year in the specified
century. If the century is specified but the year is not, the first
year of the century is assumed.
update
So in your case you should do smth like:
vao=# create table arasu (member_birth_date character(9)); insert into arasu values ('28JUN80'),('25APR48');
CREATE TABLE
INSERT 0 2
vao=# select to_timestamp(member_birth_date||' 20', 'ddmonYY cc') from arasu;
to_timestamp
------------------------
1980-06-28 00:00:00+03
1948-04-25 00:00:00+03
(2 rows)
Here is my current formula:
if left ({Command.NextDueDate},7) = "2016-01" then "January'16"
else if left ({Command.NextDueDate},7) = "2016-02" then "February'16"
...
else if left ({Command.NextDueDate},7) = "2017-01" then "January'17"
I take date Strings from my database formatted like 2016-01-05, 2016-01-06...2017-01-01. I use these as columns.
I want to look for the year (16), then month (01), then for next column look for year (16) again and month (2). Then I'd like to interpret the month as shortened month names, like Jan or Feb. Finally I'd want to join the data back together. So in the end it will work like this:
16 + 01 becomes Jan16
16 + 02 becomes Feb16
17 + 01 becomes Jan17
How can I do this without manually entering an if-else clause for each month of each year?
No need to hard code it - Use this formula to get the month and year:
MonthName(Month(CDateTime({Command.NextDueDate}))) +
Right(Left({Command.NextDueDate},4),2);
Don't use if/else statements when you can get the information through clever use of formulas. There are a few ways you can make Ankur's formula even better:
To get the short Month name, use: MonthName(Month(CDateTime({Command.NextDueDate})),True) The True at the end shortens the name to "Jan", "Feb", "Mar" and so on.
To get the Year, use Year(CDateTime({Command.NextDueDate}))
Combine the two formulas and it does all the work for you:
MonthName(Month(CDateTime({Command.NextDueDate})),True) +
Year(CDateTime({Command.NextDueDate}))
I have a table in GreenPlum (PostgreSQL) with all fields as sting, and I want to edit the types :
To do this I created a view :
CREATE VIEW typed_view AS
SELECT CAST(sid AS bigint), CAST(gid AS bigint),
...
But I have a problem with the Date and Time fields, I tried this command but it didn't work :
to_utc_timestamp(from_unixtime(unix_timestamp(eventdatetime,"yyyy-MM-dd
HH:mm:ss")),'UTC') AS eventdatetime,
After that I tried the PostgreSQL notation :
to_timestamp(eventdatetime, 'YYYY Mon DD HH24 MI SS') AS eventdatetime,
But still not working.
Anyone knows how to convert it ?
I also have this command that is not working :
CASE WHEN fix = "True" THEN TRUE ELSE FALSE END AS fix,
Thanks in advance
You didn't provide example data so I'm going to assume your data looks like "YYYY Mon DD HH24 MI SS". So January 4, 2016 at 2:15:20 PM would look like '2016 Jan 04 14 15 20' in your data. So with this example data, the conversion would look like this:
gpadmin=# select to_timestamp('2016 Jan 04 14 15 20', 'yyyy mon dd hh24 mi ss') as col1;
col1
------------------------
2016-01-04 14:15:20-05
(1 row)
Now this is a timestamp which also include the timezone offset which for my server is -5. To convert this to a timestamp without the timezone, you just add ::timestamptz.
gpadmin=# select to_timestamp('2016 Jan 04 14 15 20', 'yyyy mon dd hh24 mi ss')::timestamp as col1;
col1
---------------------
2016-01-04 14:15:20
(1 row)
A very important note on this. It is costly to convert data from a string to a different datatype. That is the same in all databases too. It is better to incur the expense of this conversion once rather than doing it for every SELECT statement. So, I also suggest you materialize this transformation into a physical table rather than using a VIEW.
I've seen threads where the document has Start Date and End Date "widgets" where users type in their dates, however, I'm looking for a dynamic solution, for example on the table below, when I select a date, say "1/1/2004", I only want to see active players (this would exclude Michael Jordan only).
Jersey# Name RookieYr RetirementYr Average PPG
23 Michael Jordan 1/1/1984 1/1/2003 24
33 Scotty Pippen 1/1/1987 1/1/2008 15
1 Derrick Rose 1/1/2008 1/1/9999 16
25 Vince Carter 1/1/1998 1/1/9999 18
The most flexible way is to IntervalMatch the RookieYr * RetireYr dates into a table of all dates. See http://qlikviewcookbook.com/recipes/download-info/count-days-in-a-transaction-using-intervalmatch/ for a complete example.
Here's the interval match for your data. You'll can obviously create your calendar however you want.
STATS:
load * inline [
Jersey#, Name, RookieYr, RetirementYr, Average, PPG
23, Michael Jordan, 1/1/1984, 1/1/2003, 24
33, Scotty Pippen, 1/1/1987, 1/1/2008, 15
1, Derrick Rose, 1/1/2008, 1/1/9999, 16
25, Vince Carter, 1/1/1998, 1/1/9999, 18
];
let zDateMin=37000;
let zDateMax=40000;
DATES:
LOAD
Date($(zDateMin) + IterNo() - 1) as [DATE],
year( Date($(zDateMin) + IterNo() - 1)) as YEAR,
month( Date($(zDateMin) + IterNo() - 1)) as MONTH
AUTOGENERATE 1
WHILE $(zDateMin)+IterNo()-1<= $(zDateMax);
INTERVAL:
IntervalMatch (DATE) load RookieYr, RetirementYr resident STATS;
left join (DATES) load * resident INTERVAL; drop table INTERVAL;
There's not much to it you need to load 2 tables one with the start and end dates and one with the calendar dates then you interval match the date field to the start and end field and from there it will work the last join is just to tidy up a bit.
The result of all of that is this ctrl-t. Don't worry about the Syn key it is required to maintain the interval matching.
Then you can have something like this.
Derrick Rose is also excluded since he had not started by 1/1/2004