Microsoft Access query using the alternative of ROW_NUMBER for duplicate date - sql

Obviously there are a bunch of questions about ROW_NUMBER in MS Access and the usual response is that it does not exist but instead to use a COUNT(*) to create something similar. Unfortunately, doing so does not give me the results that I need.
My data looks like:
employee_id -------start_time ------- start_date
000670 -----------------12:30 ------------ 2019/03/28
000670 -----------------11:22 ------------ 2019/03/30
000676 -----------------13:00 ------------ 2019/03/28
000676 -----------------11:30 ------------ 2019/03/29
000676 -----------------14:00 ------------ 2019/03/29
000676 -----------------11:20 ------------ 2019/03/30
000676 -----------------14:00 ------------ 2019/03/30
000676 -----------------11:00 ------------ 2019/03/31
000677 -----------------11:20 ------------ 2019/03/28
000677 -----------------12:20 ------------ 2019/03/29
000678 -----------------12:00 ------------ 2019/03/29
Using the COUNT(*) I get:
employee_id -------- start_date ------- seq
000670 ------------ 2019/03/28 ------- 1
000670 ------------ 2019/03/30 ------- 2
000676 ------------ 2019/03/28 ------- 1
000676 ------------ 2019/03/29 ------- 3
000676 ------------ 2019/03/29 ------- 3
000676 ------------ 2019/03/30 ------- 5
000676 ------------ 2019/03/30 ------- 5
000676 ------------ 2019/03/31 ------- 6
000677 ------------ 2019/03/28 ------- 1
000677 ------------ 2019/03/29 ------- 2
000678 ------------ 2019/03/29 ------- 1
My current query is:
SELECT tbl.employee_id
, tbl.start_date
, ( SELECT COUNT(*)
FROM tbl AS tbl2
WHERE tbl2.employee_id = tbl.employee_id
AND tbl2.start_date <= tbl.start_date ) AS seq
FROM tbl
ORDER BY tbl.employee_id, tbl.start_date
What I am trying to get at is a unique count over employee_id and start_date so that my query output looks like:
employee_id -------- start_date ------- seq
000670 ------------ 2019/03/28 ------- 1
000670 ------------ 2019/03/30 ------- 2
000676 ------------ 2019/03/28 ------- 1
000676 ------------ 2019/03/29 ------- 2
000676 ------------ 2019/03/29 ------- 3
000676 ------------ 2019/03/30 ------- 4
000676 ------------ 2019/03/30 ------- 5
000676 ------------ 2019/03/31 ------- 6
000677 ------------ 2019/03/28 ------- 1
000677 ------------ 2019/03/29 ------- 2
000678 ------------ 2019/03/29 ------- 1

Please try this.
FOR SQL
SELECT
tbl.employee_id, tbl.start_date,
ROW_NUMBER() OVER(PARTITION BY employee_id ORDER BY employee_id)As Row_Num
FROM tbl
FOR MS ACCESS
SELECT tbl.employee_id
, tbl.start_date
, ( SELECT COUNT(*)
FROM tbl AS tbl2
WHERE tbl2.employee_id = tbl.employee_id
AND tbl2.start_date+tbl2.start_time < tbl.start_date+tbl.start_time
)+1 AS seq
FROM tbl

Related

get average of subtotal and wet with respect to distinct purchaseorderid and product category in DAX

i don't know where to start, pretty new in power bi or Dax
here is sample data
PurchaseOrderId SubTotal Wet ProductCategory
------------------ ----------- ----------- ------------------
1021 804.9767 233.4432 Wine
------------------ ----------- ----------- ------------------
1022 228.4651 66.2548 Beer
------------------ ----------- ----------- ------------------
1022 228.4651 66.2548 RTD
------------------ ----------- ----------- ------------------
1022 228.4651 66.2548 Wine
------------------ ----------- ----------- ------------------
1023 2791.2558 809.4641 Wine
------------------ ----------- ----------- ------------------
1023 2791.2558 809.4641 Beer
------------------ ----------- ----------- ------------------
1023 2791.2558 809.4641 Non-alcoholic
------------------ ----------- ----------- ------------------
1023 2791.2558 809.4641 RTD
------------------ ----------- ----------- ------------------
1024 396 114.84 Wine
------------------ ----------- ----------- ------------------
1025 374.2325 108.5274 Wine
------------------ ----------- ----------- ------------------
1026 864.093 250.5869 Wine
------------------ ----------- ----------- ------------------
1027 127.9069 37.093 Wine
what i want is i want average order value i.e
(Subtotal+Wet)/Count(Distinct PurchaseOrderId).
For this table Sum of distinct Subtotal is 5586.93 and Sum of
distinct wet is 1620.20,
total number of distinct purchaseorderid i.e number of orders is 7 so my average order value is (5586.93+1620.20)/7 = 1029.59,
i also want average order value by category
i am doing everything in DAX
so how this can be achieved?
Thanks in advance
You need to use this measure: I called my table (Test00) You can use yours in the same way.
AverageOfSubTotal =
VAR TblSummary = ADDCOLUMNS(
SUMMARIZE (Test00, Test00[PurchaseOrderId], Test00[ProductCategory]),
"Total_SubTotal",CALCULATE(SUM(Test00[SubTotal]))
)
RETURN
AVERAGEX(TblSummary,[Total_SubTotal])
If we test it on a table visual:
Now let's test the visual table report performance on DAX Studio:
The results are quite good!! 5 ms query time (4ms FE, 1 ms SE). 4 SE(Storage Engine) queries.
Use this as a new Measure
Avg Subtotal =
AVERAGEX(
SUMMARIZE(
'Table',
'Table'[PurchaseOrderId],
'Table'[ProductCategory],
'Table'[SubTotal]
),
'Table'[SubTotal]
)

About resource limitation (MaxSubmitJob) in Slurm

I used the following command to set the maximum number of jobs a user can run.
However, the above setting did not work.
If anyone has any knowledge about this, could you please help me.
sacctmgr modify user account=<ldap-groupname> <ldap-username> set MaxSubmitJobs=2
I checked setting following command
sacctmgr show associations
outputs
Cluster Account User Partition Share Priority GrpJobs GrpTRES GrpSubmit GrpWall GrpTRESMins MaxJobs MaxTRES MaxTRESPerNode MaxSubmit MaxWall MaxTRESMins QOS Def QOS GrpTRESRunMin
---------- ---------- ---------- ---------- --------- ---------- ------- ------------- --------- ----------- ------------- ------- ------------- -------------- --------- ----------- ------------- -------------------- --------- -------------
clustername root 1 normal
clustername root root 1 normal
clustername ldap-groupname 1 normal
clustername ldap-groupname ldap-username 1 2 normal
`
Make sure AccountingStorageEnforce is set to limits in slurm.conf.

Oracle Selecting four table's values with comma-separated values

I have four tables which names are APP_PROFILE, ORIG, TERM and TERM_FAIL. I want to select their values and separate them with a comma. By the way, I find listagg function but as far I understand listagg function cant work multiple columns.
My tables as follows;
Table: APP_PROFILE
-----------------------
ID NAME
-- ------------
1 profile_anil
2 profile_anil2
Table: ORIG
-----------------------
PROFILE_NAME ORIG_ID
------------ ---------
profile_anil 3
profile_anil 4
profile_anil2 5
profile_anil2 6
Table: TERM
-----------------------
PROFILE_NAME TERM_ID
------------ ---------
profile_anil 7
profile_anil 8
profile_anil2 9
profile_anil2 10
Table: TERM_FAIL
-----------------------
PROFILE_NAME TERM_FAIL_ID
------------ -------------
profile_anil 11
profile_anil 12
profile_anil2 13
profile_anil2 14
Table: Result
-----------------------
PROFILE_NAME ORIG_ID TERM_ID TERM_FAIL_ID
------------ --------- --------- -------------
profile_anil 3,4 7,8 11,12
profile_anil2 5,6 9,10 13,14
You can use subqueries:
select ap.*,
(select listagg(orig_id, ',') within group (order by orig_id)
from orig o
where o.profile_name = ap.profile_name
) as origs,
(select listagg(term_id, ',') within group (order by term_id)
from term t
where t.profile_name = ap.profile_name
) as terms,
(select listagg(term_fail_id, ',') within group (order by term_fail_id)
from term_fail tf
where tf.profile_name = ap.profile_name
) as term_fails
from app_profile ap;
SELECT A.PROFILE_NAME,
LISTAGG(ORIG_ID,',') ORIG_ID,
LISTAGG(TERM_ID,',') TERM_ID,
LISTAGG(TERM_FAIL_ID,',') TERM_FAIL_ID
FROM APP_PROFILE A,
ORIG B,
TERM C,
TERM_FAIL D
WHERE A.PROFILE_NAME = B.PROFILE_NAME
AND B.PROFILE_NAME = C.PROFILE_NAME
AND C.PROFILE_NAME = D.PROFILE_NAME
GROUP BY A.PROFILE_NAME

Selecting rows based on Priority -Sql

I have a case there I want to select row based Status cloumn Priorty
First Priorty should be Customer_Status with Status 'Deleted'
Second priority should be Family_Status with value 'Deleted'
[ Select top 1 with Family_Status ='Deleted']
If all Family_Status are "open' then select top 1 Family_Status ='Open'
Case : 1
CustomerID FamilyId Name Customer_Status Family_Status
------- -------- --------- --------------- -----------
1000 101 Vk Open Deleted
1000 102 vk Open Open
1000 103 vk Open Open
In this case i need result as
CustomerID FamilyId Name Customer_Status Family_Status
------- -------- --------- --------------- -----------
1000 101 Vk Open Open
Case2
CustomerID FamilyId Name Customer_Status Family_Status
------- --------- --------------- ------------
1000 101 Vk Open Open
1000 102 vk Deleted Open
1000 103 vk Open Open
In this case i need result as
CustomerID FamilyId Name Customer_Status Family_Status
------- --------- --------------- ------------
1000 102 vk Deleted Open
Case : 3
CustomerID FamilyId Name Customer_Status Family_Status
------- --------- --------------- ------------
1000 101 Vk Deleted Open
1000 102 vk Deleted Open
1000 103 vk Deleted Open
Output :
CustomerID FamilyId Name Customer_Status Family_Status
------- --------- --------------- ------------
1000 101 Vk Deleted Open
Case :4
CustomerID FamilyId Name Customer_Status Family_Status
------- --------- --------------- ------------
1000 101 Vk Open Deleted
1000 102 vk Open Deleted
1000 103 vk Open Deleted
In this case i need result as
CustomerID FamilyId Name Customer_Status Family_Status
------- --------- --------------- ---------
1000 101 Vk Open Deleted
Can anyone help on this query
Just order the result set:
SELECT TOP (1) *
FROM MyTable
ORDER BY Customer_Status, Family_Status DESC

SQL query with multiple values iteration like for each

Table: detail1
LN_ID LN_DATE LN_CATG
---------- -------- -------
1693834961 8/1/2013 16
1693834961 7/1/2013 16
1693834961 6/1/2013 4
1693834961 5/1/2013 16
1693834962 8/1/2013 16
1693834962 7/1/2013 16
1693834962 6/1/2013 16
1693834962 5/1/2013 5
Table: detail2
LN_ID LN_MOD_DATE LN_PYMT_DATE
---------- ----------- ------------
1693834961 8/1/2012 1/1/2011
1693834961 9/1/2011 2/1/2011
1693834962 10/1/2012 3/1/2012
Result:
LN_ID FIRST_DT LAST_DT LN_MOD_DT LN_PYMT_DT
---------- -------- -------- --------- ----------
1693834961 8/1/2013 6/1/2013 8/1/2012 1/1/2011
Query:
SELECT ln_id, first_dt, last_dt, ln_mod_dt, ln_pymt_dt FROM
(SELECT a.ln_id ln_id, a.ln_date first_dt,
b.ln_date last_dt, c.ln_mod_date ln_mod_dt,
c.ln_pymt_date ln_pymt_dt
FROM detail1 a,
(SELECT *
FROM (SELECT *
FROM detail1
WHERE ln_id = '1693834961'
AND ln_catg <> 16
ORDER BY ln_date DESC)
WHERE ROWNUM < 2) b,
(SELECT *
FROM (SELECT *
FROM detail2
WHERE ln_id = '1693834961'
ORDER BY ln_mod_date DESC)
WHERE ROWNUM < 2) c
WHERE a.ln_id = b.ln_id
AND a.ln_id = c.ln_id
AND a.ln_catg = 16
ORDER BY a.ln_date DESC)
WHERE ROWNUM < 2
I need to find the first(latest) and last date where the ln_catg = 16 consecutively from the detail1 table for each LN_ID.
For example the Expected ouput as ,
LN_ID FIRST_DT LAST_DT LN_MOD_DT LN_PYMT_DT
---------- -------- -------- --------- ----------
1693834961 8/1/2013 7/1/2013 8/1/2012 1/1/2011
1693834962 8/1/2013 6/1/2013 8/1/2012 1/1/2012
--------
this works seems good when the query execute against one ln_id at at time but our expectation would be this same kind of query should execute against more than one ids at a time.
is that possible add kind of for-each or adding any other where Or IN Condtion to pass the different iD's? since the ln_id hard code in the sub queries not sure how do i use one and another and execute..
any help would be apperciated.
I think this will do it?
SELECT
D1.LN_ID,
MAX(D1.LN_DATE) AS FIRST_DT,
MAX(D1_A.LN_DATE) AS LAST_DT,
MAX(D2.LN_MOD_DATE) AS LN_MOD_DT,
MAX(D2.LN_PYMT_DATE) AS LN_PYMT_DT
FROM
DETAIL1 D1
INNER JOIN DETAIL2 D2 ON D1.LN_ID=D2.LN_ID
INNER JOIN DETAIL1 D1_A ON D1_A.LN_ID=D1.LN_ID
WHERE
D1.LN_CATG = 16
AND D1_A.LN_CATG = 16
AND D1_A.LN_DATE < D1.LN_DATE
GROUP BY
D1.LN_ID