Query to select employed in a second job
My table Has EmployeeId, JobId, StartDate and EndDate.
There are three possible employment statuses:
1. Employed in their first job, therefore EndDate is NULL
2. No longer employed so their EndDate IS NOT NULL
3. Employed in a second or subsequent job. Therefore, one or more records with the EndDate NOT NULL and one record with the EndDate NULL.
How do I select out only those employees that are no longer employed but select all those that have a current job, even if they had a previous job?
Your help would be much appreciated.
Thanking you in anticipation.
Roger
rogerwithnell
>> My table Has EmployeeId, JobId, StartDate and job_end_date. <<
Please follow basic Netiquette and post the DDL we need to answer this. Follow industry and ANSI/ISO standards in your data. You should follow ISO-11179 rules for naming data elements. You should follow ISO-8601 rules for displaying temporal data. We need to
know the data types, keys and constraints on the table. Avoid dialect in favor of ANSI/ISO Standard SQL.
And you need to read and download the PDF for:
https://www.simple-talk.com/books/sql-books/119-sql-code-smells/
Since you are rude, we have to guess at everything. Why did you fail to post DDL, sample data, etc? You seem to want the typical history table idiom:
CREATE TABLE
REFERENCES Personnel(emp_id),
job_id CHAR(12) NOT NULL
REFERENCES Jobs(job_id),
job_start_date DATE DEFAULT CURRENT_TIMESTAMP NOT NULL,
job_end_date DATE,
CHECK(job_start_date <= job_end_date),
PRIMARY KEY (emp_id, job_start_date)
>> There are three possible employment statuses: <<
This is a standard SQL idiom. If you Google, you will find more constraints you need to add to the table. But since you did not follow forum rules, I feel no obligation to cut & paste it.
Do we have several job histories per employee? Can someone have overlapping jobs? How do we account for gaps in employment? If your boss is making you code from specification like this, quit.
>> How do I select out only those employees that are no longer employed … <<
SELECT emp_id AS former_emp_id
FROM Employment_History
GROUP BY emp_id
HAVING COUNT(*) = COUNT(job_end_date) ;
>> but select all those that have a current job, even if they had a previous job? <<
SELECT DISTINCT emp_id AS current_emp_id
FROM Employment_History
WHERE job_end_date IS NULL;
Study these and see why they work. Thinks sets and set-level atrtributes.
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL
Similar Messages
-
SSRS 2008 R2 is extremely slow. The query runs in less than a second in the dataset designer but if you try to view the report it takes over 10 minutes. I have read this is a bug in SSRS 2008 R2. We installed the most recent patches and
service packs. Nothing we've done so far has fixed it and I see that I'm not the only person with this problem. However I don't see any answers either.Hi Kim Sharp,
According to your description that when you view the report it is extremely slow in SSRS 2008 R2 but it is very fast when execute the query in dataset designer, right?
I have tested on my local environment and can‘t reproduce the issue. Obviously, it is the performance issue, rendering performance can be affected by a combination of factors that include hardware, number of concurrent users accessing reports, the amount
of data in a report, design of the report, and output format. If you have parameters in your report which contains many values in the list, the bad performance as you mentioned is an known issue on 2008 R2 and already have the hotfix:
http://support.microsoft.com/kb/2276203
Any issue after applying the update, I recommend you that submit a feedback at https://connect.microsoft.com/SQLServer/
If you don’t have, you can do some action to improve the performance when designing the report. Because how you create and update reports affects how fast the report renders.
Actually, the Report Server ExecutionLog2 view contains reports performance data. You could make use of below query to see where the report processing time is being spent:
After you determine whether the delay time is in data retrieval, report processing, or report rendering:
use ReportServer
SELECT TOP 10 ReportPath,parameters,
TimeDataRetrieval + TimeProcessing + TimeRendering as [total time],
TimeDataRetrieval, TimeProcessing, TimeRendering,
ByteCount, [RowCount],Source, AdditionalInfo
FROM ExecutionLog2
ORDER BY Timestart DESC
Use below methods to help troubleshoot issues according to the above query result :
Troubleshooting Reports: Report Performance
Besides this, you could also follow these articles for more information about this issue:
Report Server Catalog Best Practices
Performance, Snapshots, Caching (Reporting Services)
Similar thread for your reference:
SSRS slow
Any problem, please feel free to ask
Regards
Vicky Liu -
Hello,
I am working with Bex 3.5 WAD. How do i make use of the web item "query view selection". It is not working properly for me. Is there any document that i can follow to create a web template using the above web item. Please advise.hello Gillian,
I looked at that link before. I am able to use query view selection bex in my web template and the query drop down box is being populated by all the query views created for the query and i have given a table (table_1) as the affected web item. When i publish my template i can see the query view drop down box with the list of query views and the table. When i select one view the table is showing the results for that view, but when second view onwards the data doesn't change? what am i doing wrong. below is my html code.
<object>
<param name="OWNER" value="SAP_BW"/>
<param name="CMD" value="GET_ITEM"/>
<param name="NAME" value="ITEMVIEWDROPDOWN_1"/>
<param name="ITEM_CLASS" value="CL_RSR_WWW_ITEM_VIEW_DROP_DOWN"/>
<param name="DATA_PROVIDER" value="DATAPROVIDER_1"/>
<param name="WIDTH" value="20"/>
<param name="VIEW_DD_TARGET_ITEM" value="DP1_table"/>
<param name="VIEW_DD_RRI" value="X"/>
<param name="VIEW_DD_USE_ALL_QUERY_VIEWS" value="X"/>
<param name="VIEW_DD_DESCRIPTION_I" value="B"/>
ITEM: ITEMVIEWDROPDOWN_1
</object>
<object>
<param name="OWNER" value="SAP_BW"/>
<param name="CMD" value="GET_ITEM"/>
<param name="NAME" value="DP1_table"/>
<param name="ITEM_CLASS" value="CL_RSR_WWW_ITEM_GRID"/>
<param name="DATA_PROVIDER" value="DATAPROVIDER_1"/>
ITEM: DP1_table
</object> -
Error while executing a sql query for select
HI All,
ORA-01652: unable to extend temp segment by 128 in tablespace PSTEMP i'm getting this error while i'm executing the sql query for selecting the data.I am having 44GB of temp space, while executing the below query my temp space is getting full, Expert please let us know how the issue can be resolved..
1. I dont want to increase the temp space
2. I need to tune the query, please provide your recomendations.
insert /*+APPEND*/ into CST_DSA.HIERARCHY_MISMATCHES
(REPORT_NUM,REPORT_TYPE,REPORT_DESC,GAP,CARRIED_ITEMS,CARRIED_ITEM_TYPE,NO_OF_ROUTE_OF_CARRIED_ITEM,CARRIED_ITEM_ROUTE_NO,CARRIER_ITEMS,CARRIER_ITEM_TYPE,CARRIED_ITEM_PROTECTION_TYPE,SOURCE_SYSTEM)
select
REPORTNUMBER,REPORTTYPE,REPORTDESCRIPTION ,NULL,
carried_items,carried_item_type,no_of_route_of_carried_item,carried_item_route_no,carrier_items,
carrier_item_type,carried_item_protection_type,'PACS'
from
(select distinct
c.REPORTNUMBER,c.REPORTTYPE,c.REPORTDESCRIPTION ,NULL,
a.carried_items,a.carried_item_type,a.no_of_route_of_carried_item,a.carried_item_route_no,a.carrier_items,
a.carrier_item_type,a.carried_item_protection_type,'PACS'
from CST_ASIR.HIERARCHY_asir a,CST_DSA.M_PB_CIRCUIT_ROUTING b ,CST_DSA.REPORT_METADATA c
where a.carrier_item_type in('Connection') and a.carried_item_type in('Service')
AND a.carrier_items=b.mux
and c.REPORTNUMBER=(case
when a.carrier_item_type in ('ServicePackage','Service','Connection') then 10
else 20
end)
and a.carrier_items not in (select carried_items from CST_ASIR.HIERARCHY_asir where carried_item_type in('Connection') ))A
where not exists
(select *
from CST_DSA.HIERARCHY_MISMATCHES B where
A.REPORTNUMBER=B.REPORT_NUM and
A.REPORTTYPE=B.REPORT_TYPE and
A.REPORTDESCRIPTION=B.REPORT_DESC and
A.CARRIED_ITEMS=B.CARRIED_ITEMS and
A.CARRIED_ITEM_TYPE=B.CARRIED_ITEM_TYPE and
A.NO_OF_ROUTE_OF_CARRIED_ITEM=B.NO_OF_ROUTE_OF_CARRIED_ITEM and
A.CARRIED_ITEM_ROUTE_NO=B.CARRIED_ITEM_ROUTE_NO and
A.CARRIER_ITEMS=B.CARRIER_ITEMS and
A.CARRIER_ITEM_TYPE=B.CARRIER_ITEM_TYPE and
A.CARRIED_ITEM_PROTECTION_TYPE=B.CARRIED_ITEM_PROTECTION_TYPE
AND B.SOURCE_SYSTEM='PACS'
Explain Plan
==========
Plan
INSERT STATEMENT ALL_ROWSCost: 129 Bytes: 1,103 Cardinality: 1
20 LOAD AS SELECT CST_DSA.HIERARCHY_MISMATCHES
19 PX COORDINATOR
18 PX SEND QC (RANDOM) PARALLEL_TO_SERIAL SYS.:TQ10002 :Q1002Cost: 129 Bytes: 1,103 Cardinality: 1
17 NESTED LOOPS PARALLEL_COMBINED_WITH_PARENT :Q1002Cost: 129 Bytes: 1,103 Cardinality: 1
15 HASH JOIN RIGHT ANTI NA PARALLEL_COMBINED_WITH_PARENT :Q1002Cost: 129 Bytes: 1,098 Cardinality: 1
4 PX RECEIVE PARALLEL_COMBINED_WITH_PARENT :Q1002Cost: 63 Bytes: 359,283 Cardinality: 15,621
3 PX SEND BROADCAST PARALLEL_TO_PARALLEL SYS.:TQ10001 :Q1001Cost: 63 Bytes: 359,283 Cardinality: 15,621
2 PX BLOCK ITERATOR PARALLEL_COMBINED_WITH_CHILD :Q1001Cost: 63 Bytes: 359,283 Cardinality: 15,621
1 MAT_VIEW ACCESS FULL MAT_VIEW PARALLEL_COMBINED_WITH_PARENT CST_ASIR.HIERARCHY :Q1001Cost: 63 Bytes: 359,283 Cardinality: 15,621
14 NESTED LOOPS ANTI PARALLEL_COMBINED_WITH_PARENT :Q1002Cost: 65 Bytes: 40,256,600 Cardinality: 37,448
11 HASH JOIN PARALLEL_COMBINED_WITH_PARENT :Q1002Cost: 65 Bytes: 6,366,160 Cardinality: 37,448
8 BUFFER SORT PARALLEL_COMBINED_WITH_CHILD :Q1002
7 PX RECEIVE PARALLEL_COMBINED_WITH_PARENT :Q1002Cost: 1 Bytes: 214 Cardinality: 2
6 PX SEND BROADCAST PARALLEL_FROM_SERIAL SYS.:TQ10000 Cost: 1 Bytes: 214 Cardinality: 2
5 INDEX FULL SCAN INDEX CST_DSA.IDX$$_06EF0005 Cost: 1 Bytes: 214 Cardinality: 2
10 PX BLOCK ITERATOR PARALLEL_COMBINED_WITH_CHILD :Q1002Cost: 63 Bytes: 2,359,224 Cardinality: 37,448
9 MAT_VIEW ACCESS FULL MAT_VIEW PARALLEL_COMBINED_WITH_PARENT CST_ASIR.HIERARCHY :Q1002Cost: 63 Bytes: 2,359,224 Cardinality: 37,448
13 TABLE ACCESS BY INDEX ROWID TABLE PARALLEL_COMBINED_WITH_PARENT CST_DSA.HIERARCHY_MISMATCHES :Q1002Cost: 0 Bytes: 905 Cardinality: 1
12 INDEX RANGE SCAN INDEX PARALLEL_COMBINED_WITH_PARENT SYS.HIERARCHY_MISMATCHES_IDX3 :Q1002Cost: 0 Cardinality: 1
16 INDEX RANGE SCAN INDEX PARALLEL_COMBINED_WITH_PARENT CST_DSA.IDX$$_06EF0001 :Q1002Cost: 1 Bytes: 5 Cardinality: 1 -
In oracle rac, If user query a select query and in processing data is fetched but in the duration of fetching the particular node is evicted then how failover to another node internally?
The query is re-issued as a flashback query and the client process can continue to fetch from the cursor. This is described in the Net Services Administrators Guide, the section on Transparent Application Failover.
-
How to get all rows that are returned in inner sub query of select statemen
If a sub query in select statement returns more than one row than how to get all those returned rows in the final
output of the query .It will be all right if all column's value repeat and that multiple output of inner query comes
in another column .
How to get that ?As Frank said, you likely want a join, and likely an outer join to replicate the select in the projection. Something like:
SELECT id,stat, section, USER_ID concerned_person
FROM table_all,
left join table2
on room_id = sectoion and
sur_role = 'r001'
WHERE section IN (SELECT code
FROM t_area
WHERE dept= 'p002')An alternative, depending on where and how you are using the statement would be something like:
SQL> WITH t AS (
2 select 1 id from dual union all
3 select 2 id from dual),
4 t1 as (
5 select 1 id, 'One' descr from dual union all
6 select 1, 'Un' from dual union all
7 select 1, 'Une' from dual)
8 SELECT t.id, CURSOR(SELECT t1.id, t1.descr from t1
9 WHERE t1.id = t.id)
10 FROM t;
ID CURSOR(SELECTT1.ID,T
1 CURSOR STATEMENT : 2
CURSOR STATEMENT : 2
ID DESCR
1 One
1 Un
1 Une
2 CURSOR STATEMENT : 2
CURSOR STATEMENT : 2
no rows selectedJohn -
Need of SQL query in selecting distinct values from two tables
hi,
I need a query for selecting distinct values from two tables with one condition.
for eg:
there are two tables a & b.
in table a there are values like age,sex,name,empno and in table b valuses are such as age,salary,DOJ,empno.
here what i need is with the help of empno as unique field,i need to select distinct values from two tables (ie) except age.
can anybody please help me.
Thanks in advance,
RatheeshNot sure what you mean either, but perhaps this will start a dialog:
SELECT DISTINCT a.empno,
a.name,
a.sex,
b.salary,
b.doj
FROM a,
b
WHERE a.empno = b.empno;Greg -
Hi all,
I'm trying to pratice EJB 3 (which I learnt at school), with JSF and JPA, but i'm really stuck with that error :
Exception [TOPLINK-6094] (Oracle TopLink Essentials - 2.0 (Build b41-beta2 (03/30/2007))): oracle.toplink.essentials.exceptions.QueryException
Exception Description: The parameter name [departmentID] in the query's selection criteria does not match any parameter name defined in the query.
Query: ReadAllQuery(oracle.datamodel.Employees)
I will try to explain clearly what i'm trying to do :
In fact, i'm following that tutorial :
http://www.oracle.com/technology/obe/obe1013jdev/10131/ejb_and_jpa/master-detail_pagewith_ejb.htm
But, as i didn't have any oracle database, but had a mysql one on my machine, i decided to use that DB instead of the the oracle DB... So i created a set of example data (to replace the oracle example set) ...so i created the tables EMPLOYEE, and DEPARTMENT... with the correct relations (FK) and PK)
All was ok, i choose my "mysql-connector" (jdbc) instead of the oracle jdbc connector... so i could follow the tutorial.
My problem appears at the step 12 (of "Creating a Master-Detail JavaServer Faces Page"), when i run the file deptEmployees.jspx.
The information of the first departement displays correctly :
departmentID 1
departmentName ... etc
but it can't display the employees belonging to that department !
the error is :
JBO-29000: Exception Description: The parameter name [departmentID] in the query's selection criteria does not match any parameter name defined in the query. Query: ReadAllQuery(oracle.datamodel.Employees)
I think i understand what is the problem... I think that the query in charge of gathering the data of a specific departement need a parameter, but couldn't find it. But i don't know why :-/ I have tried many things and read the topics talking about that error... but it didn't solved the problem. I don't know anymore where to investigate.
I have created a Zip file of my work (it's an EJB/JSF Application.. with jdev 10.1.3.3.0)
(available here : http://dl.free.fr/mQ5esdQuS/EJB_appli.zip)
I would be glad if someone could take few minutes to help me.
Thank you in advance,
Thomas B (student)Hello,
This is a common mistake. Java string comparisons in TopLink are case sensitive by default, and since column names are uppercase when defaulted, TopLink cannot find the "departmentID" column name. In this case, Departments ID column defaults to "DEPARTMENTID" as required by the JPA specification.
Either change Departments id annotation to @Id
@Column(name="departmentID", nullable = false)
private Integer departmentID;or change Employees' ManytoOne annotation to:
@ManyToOne
@JoinColumn(name = "departmentID", referencedColumnName = "DEPARTMENTID")
private Departments departments;Best Regards,
Chris -
Impact of selecting "Removing Query from Selection List" in 2 channels.
HI All ,
I have customized a query in one channel (My Agreements and Contract Documents query in Master Agreements List channel) and have removed the standard query from the channel by checking the "Remove Query from Selection List" and introduced my custom query in that query group .
But it resulted in break in chain for "Master Agreements" link in "Contracts To Do List" channel as the link was pointing to standard "My Agreements and Contract Documents" query and is displaying "The query can not be executed. Contact your system administrator" when ever I click on that.
Any pointers on how to overcome above scenario wud be gr8!
Regards,
UdayHi Uday,
In order for To Do List channel to work, the query definition should be in the Master Agreement List query group. Do you still want the standard query in the To Do List? If so, you would have to leave it on the Query Group as To Do list is pointing to it. May be change the display name of the query so you can differentiate between the 2 queries. The other option is change the To Do channel to point to the custom query.
Regards,
Vikram -
Limiting Query View selections for Web reports
In web reports, users currently have Query View Selection but they want to be able to just see views that they have created and not all others.
How can this be done?
Does creating views in web and in BEX pull different auth objects or is it same? - Which objects are check in WEB views? Bex views use s_rs_comp with the QVW componenet.. but the trace does not show any log like this.Hi,
User specific protection of queries are controlled by authorization object S_RS_COMP1.
Authorization RSZOWNER = "$USER" allows the user access to activities in all the components he is an owner of.
Check out this link, the analyst 3 scenario is what you are looking for:
http://help.sap.com/saphelp_nw04/helpdata/EN/41/05453caff4f703e10000000a114084/content.htm
Regards,
Zaheer -
Reg: calling selection screen from the second list
Hi all,
How can we call the selection screen from the second screen.
Can any one help me to solve this problem.HI RJ,
Try .....
case sy-ucomm.
WHEN '&F03'.
LEAVE TO SCREEN '0'.
endcase.
after the FM for grid-display
i m using the same .....
i hav selection-screen..then alv grid screen 1 then again another screen with alv grid display..
bt in my code for first alv grid ...i m using REUSE_ALV_GRID_DISPLAY_LVC
as
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_callback_program = sy-repid
i_callback_pf_status_set = 'SET_PF_STATUS'(303)
i_callback_user_command = 'USER_COMMAND'(304)
i_grid_title = 'Reconcilation Report'(305)
is_layout_lvc = it_layout
it_fieldcat_lvc = gt_fieldcat3[]
TABLES
t_outtab = gt_msg[].
here i musing set_pf_status to add one pushbutton to the screen. in ur case u can avoid that...
after that
*& Form set_pf_status
text
-->EXTAB text
FORM set_pf_status USING extab TYPE slis_t_extab. "#EC NEEDED
SET PF-STATUS 'STANDARD_FULLSCREEN'.
*get back to Selection Screen
case sy-ucomm.
WHEN '&F03'(328).
LEAVE TO SCREEN '0'.
endcase.
ENDFORM. "set_pf_status
its working for me..
Thnx
Rohit...
Edited by: Rohit Kumar on Oct 29, 2008 3:20 PM -
CAML query to select data in specfic range
CAML query to select data in specfic range.
I have a list-A and it has a column 'Col1' which has thousands records, I want to fetch data in a specific range as:
select Col1,Col2 from list-A where Col1 > 100 and Col1 < 600Hi,
The following code with the CAML query for your reference:
using (SPSite site = new SPSite("http://spsite/"))
using (SPWeb web = site.OpenWeb())
string sQuery = @"<where><and><gt><fieldref name='Col1' /><value type='number'>100</value></gt><lt><fieldref name='Col1' /><value type='number'> 600 </value></lt></and></where>";
string sViewFields = @"<fieldref name='Col1' /><fieldref name='Col2' />";
string sViewAttrs = @"Scope='Recursive'";
var oQuery = new SPQuery();
oQuery.Query = sQuery;
oQuery.ViewFields = sViewFields;
oQuery.ViewAttributes = sViewAttrs;
SPList oList = web.Lists["ListName"];
SPListItemCollection collListItems = oList.GetItems(oQuery);
foreach (SPListItem oListItem in collListItems)
More information about the CAML:
http://msdn.microsoft.com/en-us/library/office/ms467521(v=office.15).aspx
http://msdn.microsoft.com/en-us/library/office/ms462365(v=office.15).aspx
Here is a tool will help you to build and test SharePoint CAML Queries:
https://spcamlqueryhelper.codeplex.com/
Best Regards
Dennis Guo
TechNet Community Support -
Query View Selection - Filter by owner
Hi
I'm using BW 3.5 and have the Query View Selection Web Item in my template.
I want to show in this web item only views from the user created them - the current user should only see the views he created and not all.
How is this possible?
Thx
RogerHi Roger,
You can acheive it in authorization object S_RS_COMP1.
Activity: *
Name (ID) of a reporting compo: *
Type of a reporting component: Query View
Owner (Person Responsible) for: $USER$
He will be having access of his view only.
Regards,
Kams -
Query for selecting the 4 highest marks of the student
query for selecting the 4 highest marks of the student
Guys dont start an argument,
tey this one; please
Hi,
Try this
Top 4
Select ename,
sale
From dept d,
emp e1
Where d.deptno = e1.deptno
And &p > (Select Count(e2.sal)
From emp e2
Where e2.sal > e1.sal
And e2.deptno = e1.deptno
Order By 1,2
Bottom 4
Select ename,
sale
From dept d,
emp e1
Where d.deptno = e1.deptno
And &p > (Select Count(e2.sal)
From emp e2
Where e2.sal < e1.sal
And e2.deptno = e1.deptno
Order By 1, 2
&P you use any value say 3,4,5,6
This is top N analysis
Regards
Umesh -
Query for selecting first 3 characters of name of any person
query for selecting first 3 characters of name of any person
10:52:44 SQL> SELECT SUBSTR(ename, 1, 3) first_three FROM emp;
FIRST_THREE
SMI
ALL
WAR
JON
MAR
BLA
CLA
SCO
KIN
TUR
ADA
FIRST_THREE
JAM
FOR
MIL
Ton
15 rows selected.
Elapsed: 00:00:00.00
Maybe you are looking for
-
My ipad2 has crashed. Tried to do an update last night. Upload bar moved 1cm then locked stayed like that all night. I have switched off and then on again and its prompting me to connect to itunes. Once connected it says to restore. It starts this pr
-
A configuration problem with saloris8
I installed Solaris8 for intel on my pc. When I logoned to the system, it told me that some configurations of the windows system are incomplete or incorrect. I tried doing the confuguration test with kdmconfig,but it showed the message"Out the ranage
-
Which is a better performer, the macbook air or the mac mini?
Which one performs better, the late 2013 macbook air (standard configuration: 4GB RAM, dual core i5 1,3 Ghz CPU) or the mac mini core quad core i7, 4GB RAM with a regular hard disc?
-
App won't load on Macs or Linux
I'm sure there is something very basic causing this issue, but my app only seems to work on Windows machines! A Mac user told me the "initializing" message appeared the first time she went to my site, but it only got about 3/4 of the way and then the
-
Disappearing files on import - help please.
Just trailing Ap 3 and trying to learn it's idiosyncrasies. I have 10 files in a desktop folder. I import all 10 into a new project. I work on a few with various adjustments and then delete say 6 of the originals leaving four of the originals in the