0% found this document useful (0 votes)
6 views

Queries

The document contains SQL statements to create three tables - Transactions, Audits, and Info - with columns to store app, transaction, audit, and location data. It also contains sample INSERT statements to add data to the tables. Several SELECT queries are listed to find transactions that meet certain criteria by joining data from the tables.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Queries

The document contains SQL statements to create three tables - Transactions, Audits, and Info - with columns to store app, transaction, audit, and location data. It also contains sample INSERT statements to add data to the tables. Several SELECT queries are listed to find transactions that meet certain criteria by joining data from the tables.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

CREATE TABLE Transactions(

appId CHAR(50) PRIMARY KEY NOT NULL,


transactionId CHAR(50),
status CHAR(50),
completedAt TIME,
workflowId CHAR(50),
workflowVersion CHAR(50),
platform CHAR(50),
createdAt TIME,
userEngagementDuration int,
geoLocation CHAR(50)
);

CREATE TABLE Audits(


appId CHAR(50) NOT NULL,
transactionId CHAR(50),
requestId CHAR(50) NOT NULL,
workflowId CHAR(50),
workflowVersion CHAR(50),
moduleId CHAR(50),
duration INT,
flags CHAR(50),
responseStatus CHAR(50),
code CHAR(50),
createdAT TIME,
PRIMARY KEY (appId, requestId)
);

CREATE TABLE Info(


appId CHAR(50) NOT NULL,
transactionId CHAR(50) NOT NULL,
latitude DOUBLE PRECISION,
longitude DOUBLE PRECISION,
geoLocation CHAR(50),
carrier CHAR(50),
device CHAR(50),
platform CHAR(50),
PRIMARY KEY (appId, transactionId)
);

SELECT appId FROM Audits WHERE moduleId = 'facematch' GROUP BY appId, transactionId
HAVING COUNT(DISTINCT device) > 1 AND COUNT(DISTINCT moduleId) > 1;

SELECT appId FROM Audits WHERE moduleId = 'facematch' GROUP BY appId, transactionId
HAVING COUNT(DISTINCT device) > 1;

INSERT INTO transactions (appId, transactionId, status, completedAt, workflowId,


workflowVersion, platform, createdAt, userEngagementDuration, geoLocation)
VALUES('mobikiwi', 't6',
'completed','01:35','w6','wv6','ios','16:45','45','dubai');

INSERT INTO audits (appId, transactionId, requestId, workflowId, workflowVersion,


moduleId, duration, flags, responseStatus, code, createdAT) VALUES('gpay', 't1',
'r1','w1','wv1','m1',50, 'true', 'ok','200','03:00');
INSERT INTO info (appId, transactionId, latitude, longitude, geoLocation, carrier,
device, platform) VALUES('gpay', 't1', 33.66, 55.43, 'delhi', 'airtel', 'google
pixel 6a', 'android');

Find all transactions where facematch failed on android in delhi


Find all transactions where workflowId w1 completed on ios in india
Get top 5 ok responsestatus codes for m2 in workflow w2. (m3 being module and w3
being a workflowId)
find all the transactions with failed facematch done with android platform before
13feb 2022 with responsestatus ok
Find all users who have attempted facematch more than twice on different devices.
(assume the same txnId is used across devices)

SELECT * FROM transactions t


INNER JOIN audits a ON t.appId = a.appId AND t.transactionId = a.transactionId
INNER JOIN info i ON t.appId = i.appId AND t.transactionId = i.transactionId
WHERE t.platform = 'android' AND t.geoLocation = 'delhi' AND a.moduleId = 'm2' AND
a.responseStatus = 'completed'

You might also like