SQL
我有一份球队名单,他们的比赛以及比赛得分。
示例数据:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_layout);
if (savedInstanceState != null) {
...
} else {
Fragment newFragment = new fragment_code();
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.add(R.id.fragment_frame, newFragment).commit();
}
final TextView g_header_date = (TextView) findViewById(R.id.global_header_date);
final TextView g_header_time = (TextView) findViewById(R.id.global_header_time);
Thread headerClock = new Thread() {
SimpleDateFormat header_date = new SimpleDateFormat("EEE, dd MMM yyyy");
SimpleDateFormat header_time = new SimpleDateFormat("hh:mm aa");
@Override
public void run() {
try {
while (!isInterrupted()) {
runOnUiThread(new Runnable() {
@Override
public void run() {
Date dt = new Date();
g_header_date.setText("Date: " + header_date.format(dt));
g_header_time.setText("Time: " + (header_time.format(dt)).replace(".", ""));
}
});
Thread.sleep(1000);
}
} catch (InterruptedException e) {
// ...
}
}
};
//headerClock.start();
}
public static class fragment_code extends Fragment implements View.OnClickListener {
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_layout, container, false);
}
@Override
public void onClick(View v) {
}
}
我要做的是创建一个查询以选择“家庭”#39;拥有“访问者”的团队。团队的共同点。意思是,与类似对手比赛的球队。
我尝试过交叉,但我不太清楚如何在这种独特的情况下使用它。最终结果如下:
rid gamedate hid home Home Score vid visitor Visitor Score
------------------------------------------------------------------
183 08/31/2017 4 Aliso 3 15 Beck 2
261 09/20/2017 4 Aliso 12 137 Mission 2
306 09/19/2017 4 Aliso 10 194 San 9
211 08/25/2017 25 Burrou 14 137 Mission 7
161 09/05/2017 25 Burrou 16 15 Beck 18
203 08/26/2017 25 Burrou 6 388 Pal 20
187 08/31/2017 7 Martin Luther 3 15 Beck 2
在我能够辨别出哪些团队在结果中扮演类似团队之后,我想我可以从那里开始处理数据。
虽然使用了交叉,但我完全不知道。
感谢您花点时间看一下。
答案 0 :(得分:1)
使用intersect:
使用联接和其他任何内容:
select d.* from
(
select a.rid, a.hid,a.home,a.vid,a.visitor from matches a
inner join matches b
on a.vid = b.vid
group by a.rid,a.hid,a.home,a.vid,a.vid,a.visitor
having count(*) > 1
) c
inner join matches d
on c.rid = d.rid