由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Database版 - How to write this SQL? Urgent!!!
相关主题
2个月前用过outer joinUrgent SQL problem!
What are two methods of retrieving SQL?请教一个SQL query该怎么写
求最小值对应的全记录SQL经典查询问题T-SQL Developer position open
怎样实现这个querySQL server DBA position available in CA
Urgent questionQuestions on SQL
Access 'memo' data type菜鸟急问ORACLE里FUNCTION返回ref cursor的问题
About exceptionHow to store data locally?
Help - UrgentRe: [转载] JDBC用完了oracle的large pool (memor
相关话题的讨论汇总
话题: sql话题: pid话题: ssn话题: position话题: urgent
进入Database版参与讨论
1 (共1页)
c*********l
发帖数: 17
1
If I have two relations:
Employee(SSN, salary, name) SSN is primary key
Position(pID, pName, state) pID is primary key, state is the US state in
which a position released
And one relationship which link the two tables:
EP(SSN, pID, tDate) SSN, pID is primary key. tDate is the date on which
position was taken
Now I wanna write a SQL to retrieve data that meet requirement below from the
database: List the last four positions that took place in Illinois
Please give my some ideas, thank
n********a
发帖数: 68
2
The question can be interpreted by different ways.
I took it mean that find the lastest four dates and
give me every position.
In Oracle 8.1.6 upper, you could do:
select pName from (
select position.pName,
dense_rank() over (order by EP.tDate desc nulls last) dr
from EP, Position
where EP.pID=position.pID and Position.state='Illinois'
) where dr <= 4;
If your database supports inline view and rownum, you could do
select pName from (
select position.pName
from EP, Position
where EP.pID=position.

【在 c*********l 的大作中提到】
: If I have two relations:
: Employee(SSN, salary, name) SSN is primary key
: Position(pID, pName, state) pID is primary key, state is the US state in
: which a position released
: And one relationship which link the two tables:
: EP(SSN, pID, tDate) SSN, pID is primary key. tDate is the date on which
: position was taken
: Now I wanna write a SQL to retrieve data that meet requirement below from the
: database: List the last four positions that took place in Illinois
: Please give my some ideas, thank

1 (共1页)
进入Database版参与讨论
相关主题
Re: [转载] JDBC用完了oracle的large pool (memorUrgent question
SQL,UNION问题Access 'memo' data type
求教一个数据库面试题,多对多关系表设计 (转载)About exception
msdtc 4355错误,sqlserver 不断的停止又启动Help - Urgent
2个月前用过outer joinUrgent SQL problem!
What are two methods of retrieving SQL?请教一个SQL query该怎么写
求最小值对应的全记录SQL经典查询问题T-SQL Developer position open
怎样实现这个querySQL server DBA position available in CA
相关话题的讨论汇总
话题: sql话题: pid话题: ssn话题: position话题: urgent