Sql query to get the given output
Hi Friends
My table data is given below
user transaction_date transaction_type
1 01-Aug-2011 a
1 02-Aug-2011 c
1 03-Aug-2011 a
1 03-Aug-2011 b
1 04-Aug-2011 a
1 04-Aug-2011 b
2 03-Aug-2011 a
2 03-Aug-2011 b
2 04-Aug-2011 c
2 04-Aug-2011 b
2 05-Aug-2011 a
2 05-Aug-2011 b
2 07-Aug-2011 a
2 07-Aug-2011 b
I want the count for each user as, how many times he did a transaction type 'b' immediately after transaction type a ?
Like the output for above data should be
user count
1 2
2 3
Thanks in advance :)
Assuming there was information in the transaction date to indicate the sequence of the transactions then it would be something like...
SQL> ed
Wrote file afiedt.buf
1 with t as (select 1 as usr, to_date('01-Aug-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') as transaction_date, 'a' as transaction_type from dual union all
2 select 1, to_date('02-Aug-2011 00:00:00','DD-MON-YYYY HH24:MI:SS'), 'c' from dual union all
3 select 1, to_date('03-Aug-2011 00:00:00','DD-MON-YYYY HH24:MI:SS'), 'a' from dual union all
4 select 1, to_date('03-Aug-2011 00:00:01','DD-MON-YYYY HH24:MI:SS'), 'b' from dual union all
5 select 1, to_date('04-Aug-2011 00:00:00','DD-MON-YYYY HH24:MI:SS'), 'a' from dual union all
6 select 1, to_date('04-Aug-2011 00:00:01','DD-MON-YYYY HH24:MI:SS'), 'b' from dual union all
7 select 2, to_date('03-Aug-2011 00:00:00','DD-MON-YYYY HH24:MI:SS'), 'a' from dual union all
8 select 2, to_date('03-Aug-2011 00:00:01','DD-MON-YYYY HH24:MI:SS'), 'b' from dual union all
9 select 2, to_date('04-Aug-2011 00:00:00','DD-MON-YYYY HH24:MI:SS'), 'c' from dual union all
10 select 2, to_date('04-Aug-2011 00:00:01','DD-MON-YYYY HH24:MI:SS'), 'b' from dual union all
11 select 2, to_date('05-Aug-2011 00:00:00','DD-MON-YYYY HH24:MI:SS'), 'a' from dual union all
12 select 2, to_date('05-Aug-2011 00:00:01','DD-MON-YYYY HH24:MI:SS'), 'b' from dual union all
13 select 2, to_date('07-Aug-2011 00:00:00','DD-MON-YYYY HH24:MI:SS'), 'a' from dual union all
14 select 2, to_date('07-Aug-2011 00:00:01','DD-MON-YYYY HH24:MI:SS'), 'b' from dual
15 )
16 --
17 -- end of test data
18 --
19 select usr, sum(sum_ab) as sum_ab
20 from (
21 select usr
22 ,case when transaction_type = 'b'
23 and lag(transaction_type) over (partition by usr order by transaction_date) = 'a'
24 then 1
25 else 0
26 end as sum_ab
27 from t
28 )
29* group by usr
SQL> /
USR SUM_AB
1 2
2 3which is essentially the same as Etbin posted, but without the assumption that the ordering is by transaction_type.
Similar Messages
-
Hi,
Please provide me sql query to get df -h output. I don't have server (Solaris) access to get df -h output.
I want to check the space availability on the mount point to increase space at the tablespace level.
Thank you..sb92075 wrote:
SQL> host df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 220G 66G 144G 32% /
none 1.9G 308K 1.9G 1% /dev
none 1.9G 959M 896M 52% /dev/shm
none 1.9G 96K 1.9G 1% /var/run
none 1.9G 0 1.9G 0% /var/lock
none 1.9G 0 1.9G 0% /lib/init/rw
The "host" command executes on the client machine running sqlplus, not the server that the OP says he doesn't have access to. -
SQL query to get the Datetime 06 hours prior to the table Datetime value
Hi Experts,
I'm just trying to create a SQL query to get the Datetime which should be 06 hours prior to my Table column value(Executiontime),
Eg: my Executiontime(column) value is 07:00AM means, this query should fetch the detail of first VMName from table at 01:00AM,
SQL Table Name: TestTable
Columns: VMName(varchar),status(varchar) Executiontime(Datetime)
SQL Query : Select Top 1 VMName from
TestTable where convert(date,Exeutiontime)=convert(date,getdate()) and
status='0' and ExecutionTime > dateadd(hour,6,getdate())
Request someone to alter this Query to my requirement or give me the new one.
Regards,
Sundar
SundarHi All,
Thanks for your Prompt response. I tried the below queries, but still I don't have any luck. Actually the queries are returning the value before the condition met (say when the time difference is more than 06 hours). I want the
query to return exactly @ 06 hour difference or less than 06 hours,
Query 01: Select Top 1 VMName from TestTable where
convert(date,Exeutiontime)=convert(date,getdate())
and status='0'
and ExecutionTime >
dateadd(hour,-6,getdate())
Query 02: Select
Top 1 VMName from TestTable where
status='0'
and ExecutionTime >
dateadd(hour,-6,getdate())
Query 03: Select
Top 1 VMName from TestTable where status='0'
and ExecutionTime >
dateadd(hour,-6,ExecutionTime)
Can someone point out the mistake please.
Regards,
Sundar
Sundar -
SQL query to get the list of approvals
Hi,
Could someone let me know the SQL query to get the list of all the pending approvals for a user in OIM 11g R2.
ThanksThere are a few ways to do this:
- The easiest would be to use a Relationship Query from the CMC. To do this, go to the Universes section on the CMC, right click on the relevant universe, select tools >> Check Relationships.
- Use Query Builder. You will need more than one query to pull the information you need. You could try something like the below (for Webi)
SELECT SI_NAME, SI_WEBI, SI_DATACONNECTION FROM CI_APPOBJECTS
WHERE SI_KIND = 'universe' and SI_NAME = 'Universe Name'
This will give you a list of Webi Reports by SI_ID.
You'll need another query to list Webi report names:
SELECT SI_NAME FROM CI_INFOOBJECTS WHERE SI_ID IN (SI_ID from query above)
- This is trivial via Auditing / the Activity universe. This of course will only return reports that have already run.
Best.
Srinivas -
SQL Query to get the # of files in folders in a library
Anyone has the SQL query to list the number of files in each folders in a SharePoint library?
Technically it's a grey area of support as MS don't mind you doing it but won't help you if you encounter problems, the script is much better though.
Scratch that, the script isn't that good. It's using .items which won't work on large lists and is slow. The version below is untested but should be significantly faster and work on large lists.
$starttime = Get-Date
#Creating new site object
$siteurl = Read-Host "Enter the name of your site and press enter"
$site = New-Object Microsoft.SharePoint.SPSite($siteurl)
#Assigning all webs (sites) to $webs
$webs = $site.Allwebs
#System Libraries defined so they won't be touched##
$systemlibs =@("Converted Forms", "Customized Reports", "Documents", "Form Templates",
"Images", "List Template Gallery", "Master Page Gallery", "Pages",
"Reporting Templates", "Site Assets", "Site Collection Documents",
"Site Collection Images", "Site Pages", "Solution Gallery",
"Style Library", "Theme Gallery", "Web Part Gallery", "wfpub")
Write-Host "Total number of webs that will be traversed: " $webs.count
$DocLibsCount = 0
$DocLibwItems = 0
$totalitems = 0
$subfolderitems = 0
foreach($web in $webs)
$listcoll = $web.lists
foreach($list in $listcoll)
if($list -eq $null)
Write-Host
else
$base = $list.GetType()
if($base.name -eq "SPDocumentLibrary")
if ($systemlibs -contains $list)
{ continue}
else
$DocLibsCount += 1
$totalitems += $List.itemcount
$name = $list.Title
$folders = $web.GetFolder($name).SubFolders
for($etr = 0;$etr -lt $folders.count; $etr++)
if($folders[$etr].Name -ne "Forms")
Write-Host "Processing SubFolder ItemCount" -ForegroundColor Red
$tempcount = $folders[$etr].ItemCount
$subfolderitems += $tempcount
Write-Host
Write-Host
Write-Host "Total # of Document Libraries: " $DocLibsCount -ForegroundColor Green
Write-Host "Total # of Document Libraries that contain items: " $DocLibwItems -ForegroundColor Green
Write-Host "Total # of items: " $totalitems -ForegroundColor Green
Write-Host "Total # of items in DocLib\Subfolders: " $subfolderitems -ForegroundColor Green
$finishtime = Get-Date
Write-Host
Write-Host “Script Duration” –ForegroundColor Yellow
Write-Host “Started: “ $starttime –ForegroundColor Yellow
Write-Host “Finished: “ $finishtime –ForegroundColor Yellow
Stop-SPAssignment -Global -
OIM sql Query for getting the status of the task which got failed
Hi Everyone,
We have a requirement like we need to get the status of a particular task(say Create User in OID resource - Completed\Rejected status) for the particular user.We are able to get the status of the resource provisioed to the user but not the status of the particular task getting trigerred for the user.can someone put some light on this.We need to get the SQL query for this.
Thanks in Advance.
Regards,
MKNHi
Use this sample query to get the task status, also check the cooments
SELECT USR.USR_LOGIN, OSI.SCH_KEY,SCH.SCH_STATUS,STA.STA_BUCKET FROM
OSI,SCH,STA,MIL,TOS,PKG,OIU,USR,OBJ,OST
WHERE OSI.MIL_KEY=MIL.MIL_KEY
AND SCH.SCH_KEY=OSI.SCH_KEY
AND STA.STA_STATUS=SCH.SCH_STATUS
AND TOS.PKG_KEY=PKG.PKG_KEY
AND MIL.TOS_KEY=TOS.TOS_KEY
AND OIU.USR_KEY=USR.USR_KEY
AND OIU.OST_KEY=OST.OST_KEY
AND OST.OBJ_KEY=OBJ.OBJ_KEY
AND OSI.ORC_KEY=OIU.ORC_KEY
AND OBJ.OBJ_NAME='AD User'
AND OST.OST_STATUS = 'Provisioning' -- filter accordinglly
AND STA.STA_BUCKET = 'Pending' -- filter accordinglly
AND PKG.PKG_NAME='AD User' -- filter accordinglly
AND MIL.MIL_NAME='System Validation' ---- filter accordinglly
Thanks,
Kuldeep -
SQL query to get the monitor target on a monitor
Hi!
I have a list of some custom created Monitors. I need a list of which computers that are using the monitors, the "Monitor target". Please help me with this. It need to be a SQL Query because my powershell have stopped working.Yes that is what i have explained you with the screenshot right it is the one in your screen shot also which is mentioned as (This). If this is a default group then you will not get agents for that refer the below link on how to pull agent list of the Target
group
http://msdn.microsoft.com/en-us/library/bb960484.aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1
Or look at this. You can see what groups the agents are associated manually one by one by using the default SCOM Task.
Go to Administration==> Agent managed==> Select the agent ==> Right click it and click View ==> Select state view.
Once you select this you will have another window opened for that particular agent.
Then click on the name of the agent and on the right hand side bottom you will have a default made task to check to what group's or Targets this agent is associated to. Run that task and you will get the output.
Look at the ones highlighted in RED
Below is the screenshot for your reference. Hope this helps
Gautam.75801 -
To write a single query to get the desired output.
Hi,
I have table by name "employees" it contains 20 records meaning 20 employee details.
some of the column it contains are employee_id,Hiredate as below.
EMPLOYEE_ID|HIRE_DATE
100|6/17/1987
101|9/21/1989
102|1/13/1993
103|1/3/1993
104|5/21/1991
107|2/7/1999
124|11/16/1999
141|10/17/1995
142|1/29/1997
143|3/15/1998
144|7/9/1998
149|1/29/2000
174|5/11/1996
176|3/24/1998
178|5/24/1999
200|9/17/1987
201|2/17/1996
202|8/17/1997
205|6/7/1994
206|6/7/1994
The query should display the total number of employees, employees hired in 1995,1996,1997 and 1998 some thing like below.
output
Total 1995 1996 1997 1998
20 1 2 2 3
please let me know the query.
Thanks
DineshSQL> select * from employees;
EMPLOYEE_ID HIRE_DATE
100 17-JUN-1987 00:00:00
101 21-SEP-1989 00:00:00
102 13-JAN-1993 00:00:00
103 03-JAN-1993 00:00:00
104 21-MAY-1991 00:00:00
107 07-FEB-1999 00:00:00
124 16-NOV-1999 00:00:00
141 17-OCT-1995 00:00:00
142 29-JAN-1997 00:00:00
143 15-MAR-1998 00:00:00
144 09-JUL-1998 00:00:00
149 29-JAN-2000 00:00:00
174 11-MAY-1996 00:00:00
176 24-MAR-1998 00:00:00
178 24-MAY-1999 00:00:00
200 17-SEP-1987 00:00:00
201 17-FEB-1996 00:00:00
202 17-AUG-1997 00:00:00
205 07-JUN-1994 00:00:00
206 07-JUN-1994 00:00:00
20 rows selected.
SQL> select count(*) total_employees
2 ,sum(case when to_char(hire_date,'YYYY') = '1995' then 1 else 0 end) hired_1995
3 ,sum(case when to_char(hire_date,'YYYY') = '1996' then 1 else 0 end) hired_1996
4 ,sum(case when to_char(hire_date,'YYYY') = '1997' then 1 else 0 end) hired_1997
5 ,sum(case when to_char(hire_date,'YYYY') = '1998' then 1 else 0 end) hired_1998
6 from employees;
TOTAL_EMPLOYEES HIRED_1995 HIRED_1996 HIRED_1997 HIRED_1998
20 1 2 2 3Edited by: SomeoneElse on Jan 6, 2009 8:09 AM -
How to modify this query to get the desired output format
I hv written a Query to display all the parent table names and their primary key columns(relevant to this foreign key of the child table).The query is given below...
SELECT DISTINCT(TABLE_NAME) AS PARENT_TABLE,COLUMN_NAME AS PARENT_COLUMN
FROM ALL_CONS_COLUMNS
WHERE CONSTRAINT_NAME IN (SELECT AC.R_CONSTRAINT_NAME
FROM ALL_CONSTRAINTS AC
WHERE AC.TABLE_NAME=TABLE_NAME
AND AC.TABLE_NAME='&TABLE'
AND AC.R_CONSTRAINT_NAME IS NOT NULL);
This query will display all the parent tables and their primary key columns.Now my problem is that how to modify this query to also display the foreign key column name of the child table.
I want the query result in the following format.The query should display the following columns.1)child table's name,2)child table's foreign key column name,3)the corresponding parent table's name,4)the parent table's primary key column name(which is the foreign key in the child table).
For Example I want the output as follows...
TAKE THE CASE OF SCOTT.EMP(AS INPUT TO YOUR QUERY)
CHILD_TABLE CHILD_COLUMN PARENT_TABLE PARENT_COLUMN
EMP DEPTNO DEPT DEPTNO
In this result I hv used alias name for the columns.The query should display this only for the foreign keys in the child table.In the query which I sent to you earlier will give the parent table and the parent column names,But I also want to append the child table and child column names there.
any help on how to tackle would be appreciated.Try this query
SELECT c.table_name child_table,
c.column_name child_column,
p.table_name parent_table,
p.column_name parent_column
FROM user_constraints a,user_constraints b,user_cons_columns c,
user_cons_columns p
WHERE a.r_constraint_name=b.constraint_name and
a.constraint_name=c.constraint_name and
b.constraint_name=p.constraint_name and
c.position=p.position
ORDER BY c.constraint_name,c.position
Anwar -
SQL Query to get the desired result
Can someone give the SQL to get this output.
input is like this in table.
cola colb fromdate todate
1 100 1/5/2010 1/9/2010
1 101 1/10/2010 1/25/2010
1 102 1/26/2010 12/31/2900
2 201 3/1/2011 3/10/2011
2 202 3/11/2011 12/31/2900
3 301 1/5/2010 1/9/2010
3 302 1/10/2010 1/25/2010
3 303 1/26/2010 1/28/2010
3 304 1/29/2010 12/31/2900
I want to get the output like this.
cola colb fromdate todate
1 100 1/5/2010 1/9/2010
2 201 3/1/2011 3/10/2011
3 301 1/5/2010 1/9/2010
More info:
I want to get the rows where fromdate is the min(fromdate) from each cola's unique values i.e. 1,2,3
Please let me know the SQL.
Thanks.
[email protected]This way!!!
with data(cola, colb, st_dt, ed_dt) as
select 1, 100, to_date('01/05/2010', 'MM/DD/YYYY'), to_date('01/09/2010', 'MM/DD/YYYY') from dual union all
select 1, 101, to_date('01/10/2010', 'MM/DD/YYYY'), to_date('01/25/2010', 'MM/DD/YYYY') from dual union all
select 1, 102, to_date('01/26/2010', 'MM/DD/YYYY'), to_date('12/31/2900', 'MM/DD/YYYY') from dual union all
select 2, 201, to_date('03/01/2011', 'MM/DD/YYYY'), to_date('03/10/2011', 'MM/DD/YYYY') from dual union all
select 2, 202, to_date('03/11/2011', 'MM/DD/YYYY'), to_date('12/31/2900', 'MM/DD/YYYY') from dual union all
select 3, 301, to_date('01/05/2010', 'MM/DD/YYYY'), to_date('01/09/2010', 'MM/DD/YYYY') from dual union all
select 3, 302, to_date('01/10/2010', 'MM/DD/YYYY'), to_date('01/25/2010', 'MM/DD/YYYY') from dual union all
select 3, 303, to_date('01/26/2010', 'MM/DD/YYYY'), to_date('01/28/2010', 'MM/DD/YYYY') from dual union all
select 3, 304, to_date('01/29/2010', 'MM/DD/YYYY'), to_date('12/31/2900', 'MM/DD/YYYY') from dual
select cola, colb, st_dt, ed_dt
from (
select cola, colb, st_dt, ed_dt,
row_number() over (partition by cola order by st_dt) rn
from data
) a
where a.rn = 1;
COLA COLB ST_DT ED_DT
1 100 05-JAN-10 09-JAN-10
2 201 01-MAR-11 10-MAR-11
3 301 05-JAN-10 09-JAN-10 -
SQL query to get the without SCCM agent for a Server
Hello every one,
Can I get the SQL query for a server without a SCCM agent .Here you go!!
Add the version for windows 2012 server if you have them as well in your environment
v_R_System.Netbios_Name0
,v_R_System.Full_Domain_Name0
,v_R_System.User_Name0
,case
When v_R_System.Operating_System_Name_and0 LIKE N'%Server 6.1'THEN 'Windows Server 2008 R2'
When v_R_System.Operating_System_Name_and0 LIKE N'%Server 6.0'THEN 'Windows Server 2008'
When v_R_System.Operating_System_Name_and0 LIKE N'%Server 5.2'THEN 'Windows Server 2003 R2'
ELSE 'Unknown Version' END AS 'OS version'
FROM
v_R_System
WHERE
v_R_System.Operating_System_Name_and0 LIKE N'%server%' and v_R_System.Client0 is null
Kindly mark as answer/Vote as helpful if a reply from anybody helped you in this forum. Delphin -
SQL query to get the responsibility name
Hi,
I require an SQL query which would give the responsibilty name to which the concurrent programs are assigned.
Thanks& Regards,SELECT fcpv.user_concurrent_program_name
FROM fnd_request_groups frg,
fnd_request_group_units frgu,
fnd_concurrent_programs_vl fcpv,
fnd_responsibility_vl frv
WHERE frgu.request_group_id = frg.request_group_id
AND frgu.request_unit_id = fcpv.concurrent_program_id
AND frv.request_group_id = frg.request_group_id
AND frgu.request_unit_type = 'P'
AND frv.responsibility_name =<Responsibility Name>Regards
Prashant Pathak -
Need SQL query to get the result.
Region
Month
Trx Type
Resolution Summary
AMERICAS
May-13
Adjustments
Correct
EMEA
May-13
Adjustments
Incorrect
AMERICAS
May-13
Credit Memo
Incorrect
EMEA
May-13
Invoice
Correct
AMERICAS
May-13
Credit Memo
Correct
OFD
May-13
Adjustments
Correct
AMERICAS
May-13
Invoice
Incorrect
LAD
May-13
Adjustments
Correct
LAD
May-13
Adjustments
Correct
OFD
May-13
Adjustments
Correct
Above is my Table and find below the required result.Similarly for other regions as well. Can anyone help me with the SQL Query?
Region
Resolution Summary
Adjustment
Credit Memo
Invoice
Grand Total
AMERICAS
Correct
1
1
2
Incorrect
0
1
1
2Like this?
SQL> select * from transaction_audit;
REGION MTH TRX_TYPE RESOLUTIO
AMERICAS may-13 ADJUSTMENTS CORRECT
EMEA may-13 ADJUSTMENTS INCORRECT
AMERICAS may-13 CREDIT MEMO INCORRECT
EMEA may-13 INVOICE CORRECT
AMERICAS may-13 CREDIT MEMO CORRECT
OFD may-13 ADJUSTMENTS CORRECT
AMERICAS may-13 INVOICE INCORRECT
LAD may-13 ADJUSTMENTS CORRECT
LAD may-13 ADJUSTMENTS CORRECT
OFD may-13 ADJUSTMENTS CORRECT
10 rows selected.
SQL> select region
2 , resolution_summary
3 , count(decode(trx_type, 'ADJUSTMENTS', trx_type)) adjustments
4 , count(decode(trx_type, 'CREDIT MEMO', trx_type)) credit_memo
5 , count(decode(trx_type, 'INVOICE' , trx_type)) invoice
6 from transaction_audit
7 group
8 by region
9 , resolution_summary
10 order
11 by region
12 , resolution_summary
13 /
REGION RESOLUTIO ADJUSTMENTS CREDIT_MEMO INVOICE
AMERICAS CORRECT 1 1 0
AMERICAS INCORRECT 0 1 1
EMEA CORRECT 0 0 1
EMEA INCORRECT 1 0 0
LAD CORRECT 2 0 0
OFD CORRECT 2 0 0
6 rows selected.
SQL> -
How to get the given output format..
Hi,I want to write a code in ABAP in such a way that I should get the output in the right side format.
Ex:
1200 - > 1,200
12000 - > 12,000
120000 -> 120,000
1200000 -> 1,200,000
12000000 -> 12,000,000
120000000 - > 120,000,000
Thanks.HI tushar,
1. I don't know whether i understood u r question !
2. FOr writing with COMMA,
if we use simple WRITE,
then it will show just as u want !
regards,
amit m. -
SQL query to get the current session info
I've a query in my application to view the all the sessions within database
select
substr(a.spid,1,9) pid,
substr(b.sid,1,5) sid,
substr(b.serial#,1,5) ser#,
substr(b.machine,1,6) box,
substr(b.username,1,10) username,
-- b.server,
substr(b.osuser,1,8) os_user,
substr(b.program,1,30) program
from
v$session b,
v$process a
where
b.paddr = a.addr
and type='USER'
order by spid;
Can someone help me with a query to view the info of the session where I'm in currently?
Thanks,
Gabriel Stephen.here's one way to do it.
select
substr(a.spid,1,9) pid,
substr(b.sid,1,5) sid,
substr(b.serial#,1,5) ser#,
substr(b.machine,1,6) box,
substr(b.username,1,10) username,
-- b.server,
substr(b.osuser,1,8) os_user,
substr(b.program,1,30) program
from
v$session b,
v$process a
where
b.paddr = a.addr
and type='USER'
and b.sid=(select sid from v$mystat where rownum=1)
order by spid-------------
Anwar
Maybe you are looking for
-
Hi guru's I have executed dunning through F150, customer is over due in 46 days as on day when i run the dunning its coming 1st letter as per due it should be 4th level dunning. what is reson behind this? Is there any possibilty to run required dunni
-
Error while processing CMP beans
Hi, I have been trying to deploy my EAR on SunONE 7 since quite some time but still not successful. I feel the classpath being printed on the log is not complete, it gets truncated, i can see some special characters at the end of the classpath e.g. D
-
hi guys 'm new to ep pls tel me how to do user mapping in sap ep thanks regards kamal
-
Task is overdue in Task List - Task not active
Hello together, in our Solution Manager are several tasks in one system which are overdue but not active. So, after I've done all tasks i can't check the system as done. Which Job is responsive for updating the task list, or how can i reset the task
-
My macbook (2008 unibody, 2.4ghz, os x 10.6.8) will not stay asleep, and it restarts when I shut it down. For example, I'll close the lid, it will sleep, then wake a few seconds later, and eventually go back to sleep. After a few cycles of this, the