我有两张桌子加入了他们。现在,我需要从连接的表中选择2列,一个应该是列,如果案件有被告和原告,那么它应该显示OK,如果只有被告然后def,原告然后pltf,如果它们都没有那么。< / p>
我基本上有这种表:
export class Sum extends Component {
constructor(props) {
super(props)
this.state = {
sum: 0, buttonClicked:[false,false,false]
}
}
handleClick(buttonNumber) {
if(this.state.buttonClicked[buttonNumber-1]){
this.setState({sum:this.state.sum-1})
else
this.setState({sum:this.state.sum+1})
let x = this.state.buttonClicked;
x[buttonNumber-1] = true; //for updating buttonClicked array
this.setState({buttonClicked:x})
}
render() {
return (
<div>
<button onClick={this.handleClick.bind(this,1)}>button1</button>
<button onClick={this.handleClick.bind(this,2)}>button2</button>
<button onClick={this.handleClick.bind(this,3)}>button3</button>
</div>
)
}
我需要这个:
Personid# Case# Role CaseType
----------------------------------------------
cg902 CB190 Plaintiff Civil
cg903 CB190 Defendant Civil
cg904 CB191 Plaintiff Civil
cg905 CB192 Defendant Civil
cg906 CB193 none Civil
我真的很感激。
答案 0 :(得分:2)
将table_name替换为您的表名
此查询将解决您的要求:
select distinct y.case#,
case
when x.role='Plaintiff' and y.cnt=1 then 'PLTF'
when x.role='Defendant' and y.cnt=1 then 'Def'
when x.role='none' and y.cnt=1 then 'NONE'
when y.cnt=2 then
case
when exists(select 1 from TABLE_NAME where role='Plaintiff' and CASE#=y.case#) and
exists(select 1 from TABLE_NAME where role='Defendant' and CASE#=y.case#)
then 'OK'
end
end
from
(select case#,
count(case#) as cnt
from TABLE_NAME
group by case#
order by case#) y, TABLE_NAME x
where x.case#=y.case#
order by y.case#
;
答案 1 :(得分:0)
这样的事情(修复案例和 personID 问题):
SQL> with test (ccase, crole) as
2 (select 'cb190', 'plaintiff' from dual union
3 select 'cb190', 'defendant' from dual union
4 select 'cb191', 'plaintiff' from dual union
5 select 'cb192', 'defendant' from dual union
6 select 'cb193', 'none' from dual
7 ),
8 inter as
9 (select ccase, min(crole) minrole, max(crole) maxrole
10 from test
11 group by ccase
12 )
13 select ccase,
14 case when minrole <> maxrole then 'ok'
15 when minrole = maxrole and minrole = 'plaintiff' then 'pltf'
16 when minrole = maxrole and minrole = 'defendant' then 'def'
17 else 'none'
18 end anycolname
19 from inter
20 order by ccase;
CCASE ANYC
----- ----
cb190 ok
cb191 pltf
cb192 def
cb193 none
SQL>