In my iOS messaging app, I'd like to display a list of the newest messages a user have with his interlocutors. In other words, this view is an overview of all chats.
I found an answer for an SQL query that I've tried on the sqlite file:
SELECT m1.* FROM ZMMESSAGE m1 LEFT JOIN ZMMESSAGE m2
ON (m1.ZINTERLOCUTORUSERNAME = m2.ZINTERLOCUTORUSERNAME AND m1.ZSENTAT < m2.ZSENTAT)
WHERE m2.ZSENTAT IS NULL;
The query gives me the expected records, but how can I make an NSFetctRequest that does the same?
My entitiy is as follows:
Related
I'm having trouble getting my power bi measure to work.
I will say the report has a number of filters set for the page and [Call Direction](Same table) and [Region](another table)
I'm looking at list of calls coming into company via Cisco UCCX it has a table which logs every call that comes in, the [Node ID - Session ID - Sequence No] can be listed more than once if it not answered by an agent first time.
I can easily create a measure which distinct counts [Node ID - Session ID - Sequence No] to give me an entry once per call
measure =calculate(CALCULATE(DISTINCTCOUNT('contactcalldetail'[Node ID - Session ID - Sequence No])
That works fine and gives the expected number however I wish to only see those that have abandoned. If I try and break those out either as below or using the filter option.
abandoned calls = CALCULATE(DISTINCTCOUNT('contactcalldetail'[Node ID - Session ID - Sequence No]), 'contactcalldetail'[CallOutcome]=1 || 'contactcalldetail'[CallOutcome]=4)+0
I then get a count of all abandoned calls and not just one of each [node ID - Session ID - Sequence No].
Is anyone able to help me as to where I'm going wrong?
I managed to fix this myself i used follow by counting the distictvlaues in sub table that has each phone call that hit a CSQ
Abandonded Calls = CALCULATE(
DISTINCTCOUNT('contactqueuedetail'[Node ID - Session ID - Sequence No])+0,
FILTER('contactcalldetail',[CallOutcome]=1 || [CallOutcome]=4)
)
I'm working with the Azure Core API. Using the web based data explorer, I'm able to successfully run a query that has multiple aggregations across multiple partitions. Yet when I attempt to run such a query from my shell using the Azure client library for Python (pip install azure-cosmos==4.0.0), I get an error message. I've tried two variations of the query, where one included the partition key and one didn't. Both queries returned the same error message.
container = database.get_container_client('some_container')
query1 = "select c.fmonth, c.fquarter, c.fyear, sum(c.revenue) as actual_revenue__sum, sum(c.predicted_revenue_m1) as predicted_revenue__sum from c where c.fyear=2020 group by c.fmonth, c.fquarter, c.fyear"
query2 = "select c.fmonth, c.fquarter, c.fyear, sum(c.revenue) as actual_revenue__sum, sum(c.predicted_revenue_m1) as predicted_revenue__sum from c where c.date_start >='2020-01-01' and c.date_start < '2021-01-01' group by c.fmonth, c.fquarter, c.fyear"
res = container.query_items(query1, enable_cross_partition_query=True)
Error Message Returned:
CosmosHttpResponseError: (BadRequest) Message: {"Errors":["Cross partition query only supports 'VALUE ' for aggregates."]}
ActivityId: 4961b99e-7032-4eac-ae84-2c8cab03a496, Microsoft.Azure.Documents.Common/2.11.0
Errors out for aggregates on multiple partitions, with enable cross
partition query set to true, but no "value" keyword present
If you want to use aggregates on multiple partitions,select value count(1) from c,this will work.
But python sdk doesn't support group by now.
Refer to this document,.net sdk and js sdk support group by.Other sdk will support later.
Hope this can help you.
I would like to do some reporting on my CosmosDb
my Query is
Select Max(c.results.score) from c
That works but i want the id of the highest score then i get an exception
Select c.id, Max(c.results.score) from c
'c.id' is invalid in the select list because it is not contained in an
aggregate function
you can execute following query to archive what you're asking (thought it can be not very efficient in RU/execution time terms):
Select TOP 1 c.id, c.results.score from c ORDER BY c.results.score DESC
Group by isn't supported natively in Cosmos DB so there is no out of the box way to execute this query.
To implement this using the out of the box functionality you would need to create a new document type that contains the output of your aggregation e.g.
{
"id" : 1,
"highestScore" : 1000
}
You'd then need a process within your application to keep this up-to-date.
There is also documentdb-lumenize that would allow you to do this using stored procedures. I haven't used it myself but it may be worth looking into as an alternative to the above solution.
Link is:
https://github.com/lmaccherone/documentdb-lumenize
Let's say you have a simple customization project, which contains only integration scenarios (Xport), maybe some reports and GIs. No files, code items, ect. You publish this custom to the application, and all is well. Now you wish to see the details of this custom in the database. I notice the table CustProject. However, customization project record is not found in the table (search by the Name field). The screen SM204505 shows that the project is published, but where are the details in the database?
According to T300, the customization data for these types of items are stored in the Db. It is not applied to the website files or Db schema. So where are the details in the Db? There is a purpose I have, to look for the details outside of the application.
I think this should connect some dots if you are just looking for the sql
-- Published Projects
SELECT c.* FROM dbo.CustProject c
WHERE EXISTS (SELECT * FROM dbo.CustPublishProject WHERE ProjectID = c.ProjID)
-- Contents of project
SELECT p.Name AS ProjectName, o.* FROM dbo.CustObject o
INNER JOIN dbo.CustProject p ON p.CompanyID = o.CompanyID AND p.ProjID = o.ProjectID
CustProject is the master table of the customization project and CustObject is the detail table.
Request to list Customization Project Items:
SELECT CustProject.Name as CustomizationProjectName,
CustObject.Name as CustomizationItemName,
CustObject.Type as CustomizationItemType,
CustObject.Content as CustomizationItemFile
FROM CustProject
LEFT JOIN CustObject on CustObject.ProjectID = CustProject.ProjID
Request for file items added to the customization project file section:
SELECT CustProject.Name as CustomizationProjectName,
CustObject.Name as CustomizationItemName,
cast(UploadFileRevision.Data as varchar(max)) as TextFile,
UploadFileRevision.Data as BinaryFile
FROM CustProject
JOIN CustObject ON CustObject.ProjectID = CustProject.ProjID AND
CustObject.Type = 'File'
JOIN NoteDoc on NoteDoc.NoteID = CustObject.NoteID
JOIN UploadFile ON UploadFile.FileID = NoteDoc.FileID
JOIN UploadFileRevision ON UploadFileRevision.FileID = UploadFile.FileID AND
UploadFileRevision.FileRevisionID = UploadFile.LastRevisionID
I have an SQL query that returns 356 rows when run in a native Postgresql client (psql, Navicat, etc.), but only returns 214 rows when run inside the node.js service I'm developing. Here's the query:
SELECT discs.id AS id,
discs.is_streamable AS is_streamable,
discs.updated_at AS updated_at,
albums.title AS album_title,
'https://www.slurpie.com/albums/' || albums.slug AS album_url,
artists.name AS main_artist,
genres.name AS genre,
albums.cover_remote_url AS album_art
FROM discs
JOIN albums
ON albums.id = discs.album_id
JOIN artists
ON artists.id = albums.main_artist_id
JOIN genres
ON genres.id = albums.genre_id
JOIN users
ON users.id = discs.user_id
WHERE users.authentication_token = 'itsasecret'
ORDER BY main_artist
The node.js service is using restify and pg-query (although I've tested it with the underlying "pg" module as well with the same results).
Looking at the output from the query, I can't find any similarities between the rows that are left out when the query is run inside of node (I thought perhaps a null value in a column, or an extremely large amount of column data, special characters, etc.).
Yieldsfalsehood was on the right track.
Turns out that the node code was pointed at a recent copy of the database, similar enough that it wasn't obvious that it was a separate database, but out-of-date enough that the number of rows was different.
It wasn't until I noticed a small difference in one of the rows that was returned by both psql and the node app that the cause jumped out at me.
Occams Razor FTW! :)