I have the following query using the Invantive Query Tool connecting to NMBRS.
select e.number
, es.EmployeeId
, e.displayname
, es.ParttimePercentage
, es.startdate
from Nmbrs.Employees.EmployeeSchedules es
left
outer
join Nmbrs.Employees.Employees e
on es.EmployeeId = e.id
order
by e.displayname
, es.startdate
(I want to retrieve all mutations in part-time percentage/schedule)
However Nmbrs.Employees.Employees only shows active employees. And I need that because that shows the employee ID as shown in Nmbrs.Employees.EmployeeSchedules is not the employee ID shown in the UI rather it is an internal ID.
I did notice Nmbrs.Employees.Employees has an additional where clause (as per documentation):
Additional Where Clause:
- CompanyId
- active
The following query
select * from Nmbrs.Employees.Employees where active = 1
gives an error:
Unknown identifier 'active'.
Consider one of the following: Nmbrs.Employees.Employees.PartitionID, Nmbrs.Employees.Employees.Id, Nmbrs.Employees.Employees.Number, Nmbrs.Employees.Employees.DisplayName, Employees.Employees.PartitionID, Employees.PartitionID, PartitionID, Employees.Employees.Id.
Active isn't mentioned so I don't know if that is usable.
active is a server-side filter on Nmbrs.nl. It defaults to the value "active". Don't ask me why they choose to have an API reflect the user interface; it is weird, but it is the way it is.
To retrieve all employees from one or more companies (partitions), use:
use all
select * from employeesall
OR
select * from employeesinactive
These are recent additions to the Nmbrs.nl API tables supported.
Note that the output does NOT contain whether an employee is active. When you need that too, please use a view or:
select 'active' type
, t.*
from nmbrs..employeesactive t
union all
select 'inactive' type
, t.*
from nmbrs..employeesinactive t
Related
There are a lot of answers about this problem, but none of them retrieves the entire record, but only the ID... and I need the whole record.
So, I have a table status_changes that is composed of 4 columns:
issue_id : the issue the change refers to
id: the id of the change, just a SERIAL
status_from and status_to that are infact the status that the issue had before, and the status that the issue got then
when that is a timestamp of when this happened
Nothing too crazy, but now, I would like to have the "most recent status_change" for each issue.
I tried something like:
select id
from change
group by issue_id
having when = max(when)
But this has obviously 2 big problems:
select contains fields that are not in the group by
2 having can't contains aggregate function in this way
I thought of "ordering every group by when and using something like top(1), but I can't figure out how to do it...
Use PostgreSQL's DISTINCT ON:
SELECT DISTINCT ON (issue_id)
id, issue_id, status_from, statue_to, when
FROM change
ORDER BY issue_id, when DESC;
This will return the first result (the one with the greatest when) for each issue.
I'm trying to use the public GitHub dataset on BigQuery to count events - PushEvents, in this case - on a per repository basis over time.
SELECT COUNT(*)
FROM [githubarchive:github.timeline]
WHERE type = 'PushEvent'
AND repository_name = "account/repo"
GROUP BY pushed_at
ORDER BY pushed_at DESC
Basically just retrieve the count for a specified repo and event type, group the count by date and return the list. BigQuery validates the following, but then fails the query with a:
Field 'pushed_at' not found.
As far as I can tell from GitHub's PushEvent documentation, however, pushed_at is an available field. Anybody have examples of related queries that execute properly? Any suggestions as to what's being done incorrectly here?
The field is called repository_pushed_at, and you also probably meant to include it in the SELECT list, i.e.
SELECT repository_pushed_at, COUNT(*)
FROM [githubarchive:github.timeline]
WHERE type = 'PushEvent'
AND repository_name = "account/repo"
GROUP BY repository_pushed_at
ORDER BY repository_pushed_at DESC
I want to get Employee ID, Leave Reason, Leave type and Employee name for my internal report purpose. I wrote a SQL query to retrieve those data and I got some duplicates also.
Seems it's missing some join / foreign id mapping part missing
select
h.id as employee_id,h.name as leave_reason,
s.name,r.name as res_name
from
hr_holidays_status s,
hr_holidays h,
hr_employee e,
resource_resource r
where
h.employee_id=e.id and
h.holiday_status_id=s.id and
e.resource_id=r.id
order by
resource_id
Your query looks correct, but maybe you're getting unexpected results because the hr_holidays table contains both "Leave Requests" and "Leave Allocations". It's like a double-entry system where leave allocations increase the quantity of leave days available for an employee or an employee category, while leave requests decrease it.
Your query should probably take this distinction into account, and you might also want to filter on other fields like the state, because some of the records may not be validated yet.
Looking at the declaration of the hr.holidays model in 6.1, you will see a few noteworthy fields that could be used in your query:
type: can be Allocation ('add') to represent an increment, or Request ('remove') to represent a decrement
holiday_type: can be Employee ('employee'), in which case the employee_id column indicates which employee, or Category ('category'), in which case the category_id column indicates which category
state: New ('draft'), Waiting Approval ('confirm'), Refused ('refuse'), Waiting Second Approval ('validate1'), Approved ('validate'), Cancelled ('cancel')
Due to the way this is structured I can't bring back groups with no comments/feeds in them, unfortunately trying to invert this brings up multiple errors as CollaborationGroup does not understand the relationship it has with CollaborationGroupFeed.
Here is the query:
SELECT
c.Parent.Id,
c.Parent.OwnerId,
c.Parent.CreatedById,
c.Id,
c.ParentId,
(
SELECT
Id,
FeedItemId,
ParentId
FROM FeedComments
)
FROM CollaborationGroupFeed c
I can't do it like this though for whatever reason:
SELECT
Id,
OwnerId,
CreatedById,
(
SELECT
Id,
ParentId
FROM CollaborationGroupFeeds
),
(
SELECT
Id,
FeedItemId,
ParentId
FROM FeedComments
)
FROM CollaborationGroup
Didn't understand relationship 'CollaborationGroupFeed' in FROM part of query call.`
EDIT
So lets say I have a Group that I just created called Foo
[FOO]
Foo has one Post in it BlahPost
[FOO]
|
|_BlahPost
Lets say BlahPost has a comment (or several)
[FOO]
|
|_BlahPost
|_Comment 1
|_Comment 2
The query above will return all of this.
Now lets say I have a new Group Bar
[Bar]
Since there are NO posts/comments the query above returns nothing since I'm working from child to parent,
and parent has no posts. I am looking for a query that starts at the parent CollaborationGroup and moves
down to CollaborationFeed which will display FeedComment
Make more sense? The order is mess up, I'm working from the middle and should be working from the top
Try using Chatter in Apex, which is Chatter REST API resource actions exposed as static methods in the Apex ConnectApi namespace. It's a much easier way to access Chatter data.
http://www.salesforce.com/us/developer/docs/apexcode/Content/connectAPI_overview.htm
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_connect_api.htm
I have the following two entities (1:N) :
#Entity
public class Job {
#ManyToOne
private User user
}
and
#Entity
public class User {
#OneToMany
private Collection<Job> jobs;
}
now i want to write a named Query with jpql which gets the User(s) with the most job(s).
With the following query on the Job Entity i am able to retrieve the number of jobs for each user... but somehow i have to compare it with the number of jobs of the user which has the maximum number of jobs of all...
#NamedQuery(query="SELECT j.user, COUNT(j) FROM Job j GROUP BY j.user" )
My second idea is to write the named query on the User entity:
#NamedQuery( query="SELECT u.username FROM User u WHERE SIZE(u.jobs) = MAX ??????")
Here also i don't know how to get the number of maximum assigned jobs....
can somebody help me out?
To list the user order by job size, you can use following JQL:
from User order by jobs.size desc
Which generated the following SQL using Hibernate with HSQLDB:
select
user0_.id as id0_
from
User user0_
order by
(select
count(jobs1_.user_id)
from
Job jobs1_
where
user0_.id=jobs1_.user_id) desc
To find the max job size of the users, you can limit the JPA to list only top user with the most jobs with using TypedQuery.setMaxResults(1) of the query which generated the follwing SQL for HSQLDB:
select
user0_.id as id0_
from
User user0_
order by
(select
count(jobs1_.user_id)
from
Job jobs1_
where
user0_.id=jobs1_.user_id) desc limit ?
I found a query similar to the following successfully gave me the list of Users in descending order of the number of jobs they have:
SELECT u FROM User u LEFT JOIN FETCH u.jobs
ORDER BY u.jobs.size DESC
Then if you just get the first result, then you will be getting the User with the maximum number of jobs. Is that what you wanted?
Alternatively, to get ALL the Users that have the maximum number of jobs you could use:
SELECT u FROM User u LEFT JOIN FETCH u.jobs
WHERE u.jobs.size = (SELECT max(jobs.size) FROM User)
You probably don't need the LEFT JOIN FETCH part