How to count push events on GitHub using BigQuery? - github

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

Related

Get entire record with max field for each group

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.

Do ampersands work for user input in reports?

I have a working query that goes something like this:
Base table ACCT, link to others (listagg/subqueries) and ensure matching year("rollyear") field. Then the final step is to say which year ACCT table is in.
SELECT
FROM table ACCT
FULL OUTER JOIN table TABLE2 on ACCT.id = TABLE2.id and ACCT.rollyear= TABLE2.rollyear
...
FULL JOIN table TABLE7 on ACCT.id = TABLE7.id and ACCT.rollyear= TABLE7.rollyear
where ACCT.rollyear = extract (year from sysdate) +1
I typically use the calendar year plus one. I've been playing with using ACCT.rollyear = &rollyear to get user input... The limitation/issue I have is getting that running using the "User Defined Reports" feature.
Am I using this feature correctly? Does that only work for SQL Queries and not reports? Ive seen videos/comments about Stored Procedures and using "Accept...." but my attempts to mimic give errors and I'm not sure I'm on the right track. Thanks for any advice.
Change your query to use a bind variable:
where ACCT.rollyear = :rollyear
Then in the 'Binds' section you will see a variable with that name:
When you run your query you'll then be prompted to supply the value:

Access how to show record count of a table on a form

I want to show a variable value (record count of a table) on an Access form. I tried with a textbox by defining its control source with the following and many other internal functions but all returned only errors. Anyone can help? Thanks
select count(*) from TableName
I would also suggest the DCount domain aggregate function as suggested by Andre, but to offer an alternative, if TableName is the Record Source for your form, you can also use:
=Count(*)
To count all records in the Record Source, or:
=Count([FieldName])
To count all non-null values of a particular field in the Record Source.
You need = and domain functions.
=DCount("*", "TableName")
should work as control source.

Retrieving inactive employees

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

Can the with function be used with a GroupBy clause in Laravel Eloquent?

Can the with function be used with a GroupBy clause in Laravel Eloquent? Does it serve any purpose if I have specific items to select using the Select Clause?
Following is the query that I currently have
Order::with('Campaign')
->where('isapproved','=','Y')
->groupBy('campaign_id')
->orderBy(DB::raw('COUNT(id)','desc'))
->get(array(DB::raw('COUNT(id) as totalsales')));
The order table has a column name campaign_id which belongsTo the table named campaigns. I would like to get the total count of the sales from the order table against each campaign and need to show in the following manner.
Total Sales Campaign
-------------------------
200 Campaign1
500 Campaign2
300 Campaign3
Should I have to perform a specific select or can I access the values of the Campaign table from the above query?
If the referenced column required by the Model specified on the With function is retrieved in the SELECT clause, then the With function is taken into consideration by the above query. The rectified query will be
$groupedSalesCampaign = Order::with('Campaign')
->where('isapproved','=','Y')
->groupBy('campaign_id')
->orderBy(DB::raw('COUNT(id)','desc'))
->get(array(DB::raw('COUNT(id) as totalsales'),'campaign_id'));
This way the Campaign information can be retrieved using
foreach($groupedSalesCampaign as $campaign)
{
Log::info($campaign->foo->bar);
}
Edited.