BigQuery - Crashlytics : find all users affected by all issues - firebase

Taking account that to retrieve all users affected by a particular issue, we have to write this query :
SELECT user.id as user_id
FROM
`projectId.firebase_crashlytics.package_name_ANDROID`
WHERE
issue_id = "YOUR_ISSUE_ID"
AND application.display_version = ""
AND user.id != ""
ORDER BY
user.id;
As stated here in the 6th example : https://firebase.google.com/docs/crashlytics/bigquery-export#examples_of_crashlytics_queries
Which query does retrieve all the users affected by all issues?

If you wanted to find all the IDs for users affected by any issue - you can write a query like this:
SELECT distinct user.id as user_id
FROM
`projectId.firebase_crashlytics.package_name_ANDROID`
You can remove the filters (WHERE clauses) because you want to consider all issues. The DISTINCT clause will remove any duplicates and simply give you one record for each user

Related

Last Function in Query

So I currently have a database that keeps tracks of projects, project updates, and the update dates. I have a form that with a subform that displays the project name and the most recent update made to said project. It was brought to my attention however, that the most recent update to a project does not display correctly. Ex: shows the update date of 4/6/2017 but the actual update text is from 3/16/2017.
Doing some spot research, I then learned that Access does not store records in any particular order, and that the Last function does not actually give you the last record.
I am currently scouring google to find a solution but to no avail as of yet and have turned here in hopes of a solution or idea. Thank you for any insight you can provide in advance!
Other details:
tblProjects has fields
ID
Owner
Category_ID
Project_Name
Description
Resolution_Date
Priority
Resolution_Category_ID
tblUpdates has these fields:
ID
Project_ID
Update_Date
Update
there is no built-in Last function that I am aware of in Access or VBA, where exactly are you seeing that used?
if your sub-form is bound directly to tblUpdates, then you ought to be able to just sort the sub-form in descending order based on either ID or Update_date.
if you have query joining the two tables, and are only trying to get a single row returned from tblUpdates, then this would do that, assuming the ID column in tblUpdates is an autonumber. if not, just replace ORDER BY ID with ORDER BY Update_Date Desc
SELECT a.*,
(SELECT TOP 1 Update FROM tblUpdates b WHERE a.ID = b.PROJECT_ID ORDER BY ID DESC ) AS last_update
FROM tblProjects AS a;

SQLite: SELECT from grouped and ordered result

I'm new to SQL(ite), so i'm sorry if there is a simple answer i just were to stupid to find the right search terms for.
I got 2 tables: 1 for user information and another holding points a user achieved. It's a simple one to many relation (a user can achieve points multiple times).
table1 contains "userID" and "Username" ...
table2 contains "userID" and "Amount" ...
Now i wanted to get a highscore rank for a given username.
To get the highscore i did:
SELECT Username, SUM(Amount) AS total FROM table2 JOIN table1 USING (userID) GROUP BY Username ORDER BY total DESC
How could i select a single Username and get its position from the grouped and ordered result? I have no idea how a subselect would've to look like for my goal. Is it even possible in a single query?
You cannot calculate the position of the user without referencing the other data. SQLite does not have a ranking function which would be ideal for your user case, nor does it have a row number feature that would serve as an acceptable substitute.
I suppose the closest you could get would be to drop this data into a temp table that has an incrementing ID, but I think you'd get very messy there.
It's best to handle this within the application. Get all the users and calculate rank. Cache individual user results as necessary.
Without knowing anything more about the operating context of the app/DB it's hard to provide a more specific recommendation.
For a specific user, this query gets the total amount:
SELECT SUM(Amount)
FROM Table2
WHERE userID = ?
You have to count how many other users have a higher amount than that single user:
SELECT COUNT(*)
FROM table1
WHERE (SELECT SUM(Amount)
FROM Table2
WHERE userID = table1.userID)
>=
(SELECT SUM(Amount)
FROM Table2
WHERE userID = ?);

how to query objects lookup relationship and count records?

I have an custom Invoice object with a look-up relationship to Accounts.
I'm trying to query the data base to get the total number of invoices of the accounts where Connection_Date__c has a value (Connection_Date__c is a custom field of Accounts object)
How can I do this? The query I'm using gives me only the number of accounts but not the number of invoices.
SELECT Name,(SELECT name FROM Invoices__r) FROM Account WHERE Connection_Date__c != null
In SOQL, it's almost easier to write queries that are driven from the child rather than the parent. This is opposite of SQL
Try a query that matches this pattern:
SELECT Count() FROM ChildTable WHERE ChildTable.parentField != Null
SELECT (Parent_Api_Name_In_Child_Object),
COUNT(ID)
(Child_Realtionship_Name__r.Parent_Fields....)
FROM (Child_Object_Api_Name)
GROUP BY (Parent_Api_Name_Child_Object,
Parent Feilds with API Names)
HAVING COUNT(ID){>,<,=,{Optional}}
it is an SQL queried answer
Let me know in case of any questions

Check for duplicates in the table before inserting data into SQL Server with ASP.NET

I have got 3 columns in the table, I need to check the email field before insertion of new row, so if the email exist, it should not insert that row. Do I have to go through 2 queries to achieve that, so for instance first check :
Select count(*) FROM PRODUCT WHERE email = #email
AND THEN RUN AN INSERT
Insert INTO PRODUCT (....) VALUES (....)
Or is there any better way to achieve that ,
Any suggestions or advice will be appreciated .
Thanks
You can have an INSERT statement that checks for the condition, and only inserts something, if it doesn't already exist:
IF NOT EXISTS (SELECT * FROM dbo.Product WHERE email = #email)
INSERT INTO dbo.Product(list of columns)
VALUES(list of values)
As marc_s mentioned you may use a conditional insert into. On the other hand, using a unique constraint on your email column may be very helpful too!
Just think of the possibility to insert data without your application. There would be no rule to avoid the same email!
CREATE TABLE Product
(
xxx int NOT NULL,
xxx xxx xxx,
UNIQUE (email)
)
Just google for alter/create table(s) with unique constraints!

Community server Username issue - User Username not found in membership store does not exist

I have an error occuring frequently from our community server installation whenever the googlesitemap.ashx is traversed on a specific sectionID. I suspect that a username has been amended but the posts havn't recached to reflect this.
Is there a way a can check the data integruity by performing a select statement on the database, alternatively is there a way to force the database to recache?
This error could be thrown by community server if it finds users that aren't in the instance of MemberRoleProfileProvider.
See CommunityServer.Users AddMembershipDataToUser() as an example
UPDATE:
I Solved this problem for my case by noticing that the usernames are stored in two tables - cs_Users and aspnet_Users. Turns out somehow the username was DIFFERENT in each table. Manually updating so the names were the same fixed this problem.
Also, the user would left out of membership in the following line of the stored procedure cs_Membership_GetUsersByName:
INSERT INTO #tbUsers
SELECT UserId
FROM dbo.aspnet_Users ar, #tbNames t
WHERE LOWER(t.Name) = ar.LoweredUserName AND ar.ApplicationId = #ApplicationId
The #tbNames is a table of names comes from cs_Users(?) at some point and therefore the usernames didn't match and user was not inserted in to the result later on.
See also: http://dev.communityserver.com/forums/t/490899.aspx?PageIndex=2
Not so much an answer, but you can find the affected data entries by running the following query...
Select *
FROM cs_Posts
Where UserID Not In (Select UserID
From cs_Users Where UserAccountStatus = 2)

Resources