Pls, i need help.....
Otherwise i have to write my CV very soon...
PK : USER_ID,FROM_DATE Each user has 3 rows. I need all users but only with the last row where FROM_DATE is the last
This is the basic SQL I need. Now….. Where can we put MAX(FROM_DATE )? -
SELECT USER_ID,
-
to_char(FROM_DATE,'ddmmyyyy'),
-
NVL(SALE_CHANNEL_CODE,0),
-
NVL(PROFILE_CODE,0),
-
USER_NAME,
-
NVL(DIVISION_CODE,0),
-
NVL(REGION_CODE,0),
-
NVL( DEPARTMENT_CODE,0),
-
NVL(STORE_NUM, 0),
-
NVL(SECTION_CODE,0),
-
NVL(ROLE_CODE,0),
-
STATUS
-
FROM NAM_USERS_MANAGE
-
WHERE DIVISION_CODE IN (1,3) AND USER_ID IN ( SELECT USER_ID
-
FROM NAM_USERS )
-
I took one example from the Internet : -
SELECT t.EmployeeId, t.ReviewDate, t.ReviewRating
-
FROM tbl_stuff t
-
INNER JOIN (
-
SELECT EmployeeId, MAX(ReviewDate) AS MaxReviewDate
-
FROM tbl_stuff GROUP BY EmployeeId
-
) t1 ON t.EmployeeId = t1.EmployeeId AND t.ReviewDate = t1.MaxReviewDate
-
WHERE (some filters on t)
-
But I've got "SQL Command was not properly ended"
So I took another one from the Internet: -
SELECT P.*
-
FROM (SELECT USER_ID, MAX(FROM_DATE) AS FROM_DATE
-
FROM NAM_USERS_MANAGE
-
GROUP BY USER_ID) AS O
-
INNER JOIN
-
NAM_USERS_MANAGE AS P
-
ON P.USER_ID = O.USER_ID
-
P.FROM_DATE = O.FROM_DATE;
-
And I've got "SQL Command was not properly ended" again.
So I thought maybe its related to SQL 2005 or something sp I took this one: -
select EmployeeID, ReviewDate, ReviewRating
-
from
-
(select EmployeeID, ReviewDate, ReviewRating, rank() over (partition by EmployeeID order by ReviewDate desc) as rank
-
from tbl_Stuff
-
where EmployeeID = X) a
-
where rank = 1
-
But it gives me all the data and I have no idea what is RANK...
2 13935
Pls, i need help.....
Otherwise i have to write my CV very soon...
PK : USER_ID,FROM_DATE Each user has 3 rows. I need all users but only with the last row where FROM_DATE is the last
This is the basic SQL I need. Now….. Where can we put MAX(FROM_DATE )?
SELECT USER_ID,
to_char(FROM_DATE,'ddmmyyyy'),
NVL(SALE_CHANNEL_CODE,0),
NVL(PROFILE_CODE,0),
USER_NAME,
NVL(DIVISION_CODE,0),
NVL(REGION_CODE,0),
NVL( DEPARTMENT_CODE,0),
NVL(STORE_NUM, 0),
NVL(SECTION_CODE,0),
NVL(ROLE_CODE,0),
STATUS
FROM NAM_USERS_MANAGE
WHERE DIVISION_CODE IN (1,3) AND USER_ID IN ( SELECT USER_ID
FROM NAM_USERS ) I took one example from the Internet :
SELECT t.EmployeeId, t.ReviewDate, t.ReviewRating
FROM tbl_stuff t
INNER JOIN (
SELECT EmployeeId, MAX(ReviewDate) AS MaxReviewDate
FROM tbl_stuff GROUP BY EmployeeId
) t1 ON t.EmployeeId = t1.EmployeeId AND t.ReviewDate = t1.MaxReviewDate
WHERE (some filters on t) But I've got "SQL Command was not properly ended"
So I took another one from the Internet:
SELECT P.*
FROM (SELECT USER_ID, MAX(FROM_DATE) AS FROM_DATE
FROM NAM_USERS_MANAGE
GROUP BY USER_ID) AS O
INNER JOIN
NAM_USERS_MANAGE AS P
ON P.USER_ID = O.USER_ID
P.FROM_DATE = O.FROM_DATE; And I've got "SQL Command was not properly ended" again.
So I thought maybe its related to SQL 2005 or something sp I took this one:
select EmployeeID, ReviewDate, ReviewRating
from
(select EmployeeID, ReviewDate, ReviewRating, rank() over (partition by EmployeeID order by ReviewDate desc) as rank
from tbl_Stuff
where EmployeeID = X) a
where rank = 1
But it gives me all the data and I have no idea what is RANK...
Try the following: -
SELECT USER_ID,
-
to_char(FROM_DATE,'ddmmyyyy'),
-
NVL(SALE_CHANNEL_CODE,0),
-
NVL(PROFILE_CODE,0),
-
USER_NAME,
-
NVL(DIVISION_CODE,0),
-
NVL(REGION_CODE,0),
-
NVL( DEPARTMENT_CODE,0),
-
NVL(STORE_NUM, 0),
-
NVL(SECTION_CODE,0),
-
NVL(ROLE_CODE,0),
-
STATUS
-
FROM NAM_USERS_MANAGE OUTER
-
WHERE DIVISION_CODE IN (1,3) AND USER_ID IN ( SELECT USER_ID
-
FROM NAM_USERS)
-
AND DATE_FROM = (SELECT MAX(DATE_FROM) FROM NAME_USERS_MANAGE INNER
-
WHERE OUTER.USER_ID=INNER.USER_ID )
-
GROUP BY USER_ID
-
I hope this solves your problem.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: NBaker |
last post by:
I have 1 table 'Data' and i need to select the max date. The table contains multiple rows per URN so I need all the fields where the date is most recent.
URN £ Date Gift Type ...
|
by: 400NEWBIE |
last post by:
Hi everyone, I'm having trouble figuring out how to select the max date in MS ACCESS from an AS400 table with a composite key.
Here's my data:
Type Name Select-Rule Error-Rule Effec-Date...
|
by: Freddie |
last post by:
Hello everyone:
i am trying to compare a MAX(DATE) from one table that would be greater
than a date in another.
first_table
compname MYDATE
abc comp 2006-09-26 09:19:43.250
|
by: robtyketto |
last post by:
Is there anyway to change the max date to
datenow + 2 years
I tried this in the properties -> Format -> MaxDate = dateadd("yyyy",2,date())
without success :(
Can anyone help.
Thanks, a...
|
by: Matik |
last post by:
Hello Everybody,
I have a problem, with select stmt:
SELECT TOP 15 *
FROM oaVIEW_MainData AS TOP_VIEW,
oaLanguageData_TAB AS RwQualifierJoin with (nolock)
WHERE (c_dateTime>='2007.01.10...
|
by: Anne150585 |
last post by:
Hi,
I was wandering if anyone could give me some help...
The idea is that I want to create a stored procedure that will check a bunch of tables and give me the latest 'LastUpdated' field
...
|
by: abetancur |
last post by:
I have the following code:
SELECT MAX(INVENTORY_TRANSACTION_HIST.DATE_APPLIED) AS LAST_TRANS, INVENTORY_TRANSACTION_HIST.PART_NO
FROM INVENTORY_TRANSACTION_HIST INNER JOIN
...
|
by: Inbaraj |
last post by:
Hi...
I have a Table in that i have inserted the DATE as VARCHAR now in that i Want to get the Max Date. I am new to MySQL Plz help me how to find the max date.
with regard
Inbaraj.D
|
by: sbettadpur |
last post by:
hello
Let me explain first the table structure.
table - > pds
fields - >District_ID, W_ID, Commodity_ID, Distribution_Cat_ID, Date, OB, Closing_Stock
here i want the Closing_Stock value...
|
by: janieavis |
last post by:
If I run this query I can see there are 2 records with the dates 10 August 2009 and 24 August 2009:
SELECT dbo_JobMain.BpaMainPKey, dbo_JobMain.JobDefinitionPKey, dbo_JobMain.Value,...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |