Extract out Year column and Display Year column in Horizontal column from the same query in postgres sql
Date : March 29 2020, 07:55 AM
hope this fix your issue I have this query that returns correct result for me . , Modern, explicit JOIN's, year-stuff in a derived table: select name,
count(case when year = 2002 then 1 end) as Year2002,
count(case when year = 2003 then 1 end) as Year2003,
...
count(case when year = 2016 then 1 end) as Year2016
FROM
(
SELECT companies.name,
date_part('year', scopes.time_stamp) AS Year
FROM companies companies
JOIN value_scopes value_scopes ON value_scopes.company_id = companies.company_id
JOIN dp_values dp ON value_scopes.value_scope_id = dp.value_scope_id
JOIN dp_content_definition cd ON dp.dp_content_definition_id = cd.dp_content_definition_id
JOIN dp_definition def ON def.dp_definition_id=cd.dp_definition_id
WHERE value_scopes.is_partial = 'f'
) dt
group by name
ORDER BY name
|
Swift: unexpected behavior when setting DateComponents year
Date : March 29 2020, 07:55 AM
I hope this helps you . If you log now and dc you will see the problem. now is being created from a Date. This fills in all of the date components including yearForWeekOfYear and several of the weekday related components. These components are causing modDate to come out incorrectly. newDate works as expected because only the specific components are being set. now.yearForWeekOfYear = nil
let mod = DateComponents()
mod.timeZone = now.timeZone
mod.year = 2010
mod.month = 2
mod.day = 24
mod.hour = now.hour
mod.minute = 0
mod.second = now.second
print("\nModified Date:")
print("\(mod.month!)/\(mod.day!)/\(mod.year!) \(mod.hour!):\(mod.minute!):\(mod.second!) \(mod.timeZone!)")
let modDate = calendar.date(from: mod)
print("\(modDate!)")
|
Syntax error in Python 3.7: in line "if (year % 4) and (year % 100) and (year % 400):"
Date : March 29 2020, 07:55 AM
wish help you to fix your issue That line itself is fine. You're missing a closing parenthesis on the line before it: year = int(input("Enter a year: ")
^^^^
|
How do i transform calendar year column to multiple year to months column based on months column and calendar year colum
Date : March 29 2020, 07:55 AM
To fix this issue Not sure if this will be better approach but you can achieve your output using case statement as well if you don't want to do pivot/unpivot. Data Creation: select 1 as ID, 2017 as MOYEar, 2017 as calenderyear, 1 as Jan, 2 as feb,
4 as mar, 0 as dece into #temp union all
select 1 as ID, 2017 as MOYEar, 2018 as calenderyear, 1 as Jan, 0 as feb,
6 as mar, 10 as dece union all
select 2 as ID, 2018 as MOYEar, 2018 as calenderyear, 80 as Jan, 5 as feb,
8 as mar, 22 as dece union all
select 3 as ID, 2017 as MOYEar, 2018 as calenderyear, 30 as Jan, 12 as feb,
0 as mar, 3 as dece
Select ID, MOYEar, max(case when calenderyear = '2017' then Jan else null end) as Jan_17,
max(case when calenderyear = '2017' then Feb else null end ) as Feb_17,
max(case when calenderyear = '2017' then Mar else null end ) as Mar_17,
max(case when calenderyear = '2017' then Dece else null end) as Dece_17,
max(case when calenderyear = '2018' then Jan else null end ) as Jan_18,
max(case when calenderyear = '2018' then Feb else null end ) as Feb_18,
max(case when calenderyear = '2018' then Mar else null end ) as Mar_18,
max(case when calenderyear = '2018' then Dece else null end) as Dece_18 from #temp
Group by ID, MOYEar
ID MOYEar Jan_17 Feb_17 Mar_17 Dece_17 Jan_18 Feb_18 Mar_18 Dece_18
1 2017 1 2 4 0 1 0 6 10
3 2017 NULL NULL NULL NULL 30 12 0 3
2 2018 NULL NULL NULL NULL 80 5 8 22
|
y in DATEADD function does not work for year. Instead I can use yy or year. However m and d works. Why?
Date : March 29 2020, 07:55 AM
|