我的脑袋已经开始旋转,我需要你的帮助。
我的数据库
DB:
public class PojoSpinnerAdapter extends ArrayAdapter<Pojo> {
private Activity activty;
private ArrayList<Pojo> pojoList;
LayoutInflater inflater;
public PojoSpinnerAdapter(Activity activity, int resource,
ArrayList<Pojo> pojoList) {
super(activity, resource, pojoList);
this.activty = activity;
this.pojoList = pojoList;
inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
return getCustomView(position, convertView, parent);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
return getCustomView(position, convertView, parent);
}
public View getCustomView(int position, View convertView, ViewGroup parent) {
View row = inflater.inflate(R.layout.taxo_spinner_item, parent, false);
Pojo pojo = pojoList.get(position);
//.... blah blah
return row;
} }
我想做什么
{{link-to 'posts.show' post tagName='button'}}
Show
{{/link-to}}
所以我应该只获得PID 2。
编辑:PID不是ID,它只是一个示例代码,可以是字符串:&#39; 002451&#39;我正在寻找具有相同CODES的其他PID(例如PID | CODE 1 | CODE 2 | CODE 3 | CODE 4 | CODE 5 | CODE X (up to 9) | ID
-------------------------------------------------------------------------
1 | a | b | c | | | | 1
2 | a | | b | d | | | 2
3 | x | | | | | y | 3
有select PID = 1 from first table
and retrieve all PIDs from second table
IF
selected PID's column CODE 1
or
selected PID's column CODE 2 (which is b) etc (up to 9).
= any PID's CODE X
因此它应该找到PID1
因为其code = a
列之一包含{{1} }})
MY ATTEMPT
PID2
我结束了大量查询 - 超过 81条件。在性能方面......好吧,它没有用。
我直觉地知道我应该:
如何有效地编写SQL /设计DB?
答案 0 :(得分:1)
评论太长了。
正确的数据结构是每pid
和code
一行。最简单的方法是:
create table PCodes (
pid int not null,
code varchar(255),
constraint fk_PCodes_pid references p(pid)
);
然后您将值放在一列中,检查匹配代码会更加简单。
实际上,你应该有三个表:
create table Codes (
CodeId int not null auto_increment primary key,
Code varchar(255)
);
create table PCodes (
pid int not null,
codeid int not null,
constraint fk_PCodes_pid references p(pid),
constraint fk_PCodes_codeid references codes(codeid);
);
如果代码的顺序对每个&#34; p&#34;都很重要,那么请在priority
表中添加ordering
或PCodes
列。