过滤掉约翰 [英] filter out John

查看:64
本文介绍了过滤掉约翰的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我有一个存储人员及其所属群组的数据库。因此,我
创建了三个表,一个组表,一个人表和联接表。


我有下一个表格:


GROUP(id,gname)

1名志愿者

2名工人

3生病


PERSON(id,pname)

1 John

2 Pete

3 Steve


JOIN_PERS_GROUP(id,pname,gname)

1 John,生病

2 John,工人

3 Pete,志愿者

4史蒂夫,生病


查询:

SELECT姓名来自人

LEFT JOIN join_pers_group使用pname

LEFT JOIN组使用gname

WHERE gname!=''病人''


退货

2 John ,工人

3 Pete,志愿者


而John也生病了。如何过滤掉约翰?


提前致谢,

Sjoerd

Hi all,

I have a database storing persons and the groups they belong to. I therefore
created three tables, a group table, person table and join table.

I have for example the next tables:

GROUP(id,gname)
1 volunteer
2 worker
3 sick

PERSON(id,pname)
1 John
2 Pete
3 Steve

JOIN_PERS_GROUP(id, pname, gname)
1 John, sick
2 John, worker
3 Pete, volunteer
4 Steve, sick

Query:
SELECT name FROM person
LEFT JOIN join_pers_group USING pname
LEFT JOIN group USING gname
WHERE gname!=''sick''

Returns
2 John, worker
3 Pete, volunteer

while John is also sick. How can I filter out John?

Thanks in advance,
Sjoerd

推荐答案

Sjoerd Mulder写道:
Sjoerd Mulder wrote:
大家好,

我有一个存储人员及其所属群组的数据库。因此我创建了三个表,一个组表,一个人表和联接表。

我有下一个表:

GROUP(id,gname)
1名志愿者2名工人
3名病人

PERSON(id,pname)
1 John
2 Pete
3 Steve

JOIN_PERS_GROUP(id,pname,gname)
1 John,生病
2 John,工作人员
3 Pete,志愿者
4 Steve,生病了查询:
SELECT姓名FROM人
LEFT JOIN join_pers_group使用pname
LEFT JOIN组使用gname
WHERE gname!=''病人''
返回
2 John,工作人员
3 Pete,志愿者

而John也生病了。我如何过滤掉约翰?

提前致谢,
Sjoerd
Hi all,

I have a database storing persons and the groups they belong to. I therefore
created three tables, a group table, person table and join table.

I have for example the next tables:

GROUP(id,gname)
1 volunteer
2 worker
3 sick

PERSON(id,pname)
1 John
2 Pete
3 Steve

JOIN_PERS_GROUP(id, pname, gname)
1 John, sick
2 John, worker
3 Pete, volunteer
4 Steve, sick

Query:
SELECT name FROM person
LEFT JOIN join_pers_group USING pname
LEFT JOIN group USING gname
WHERE gname!=''sick''

Returns
2 John, worker
3 Pete, volunteer

while John is also sick. How can I filter out John?

Thanks in advance,
Sjoerd




但约翰也是工人,所以你在你的名单上得到了工作的约翰。你有...... b $ b要么决定约翰是否生病,他就不能两者兼而有之,只要他在两个团体中出现
,他就会出现在两个人身上;工作者QUOT;和生病的查询。


我认为您的数据库构建错误,我建议:


group(id,gname)

1名志愿者

2名工人

3未知


人(id,pname)

1 John

2 Pete

3 Steve


能力(id,aname)

1工作

2下班

3生病

join_tables(pid,gid,aid)/ * pid和gid是主要的

键 * /

1 2 3

2 1 1

3 3 3


选择人。 pname FROM join_tables

LEFT RIGHT person ON join_tables.pid = person.id

LEFT JOIN能力ON join_tables.aid = ability.id

WHERE ability.aname!=''生病''


(认为它应该有效并给出以下结果)


彼得


// Aho



But John is worker too, so you get the working John on your list. You have
either decide if John is sick or not, he can''t be both and as long as he
appears on both groups, he will appear on both "worker" and "sick" querries.

I think your database is built up wrongly and I would have suggested:

group(id,gname)
1 volunteer
2 worker
3 UNKNOWN

person(id,pname)
1 John
2 Pete
3 Steve

ability(id,aname)
1 working
2 off duty
3 sick

join_tables(pid, gid, aid) /* the combination of pid and gid is the "primary
key" */
1 2 3
2 1 1
3 3 3

SELECT person.pname FROM join_tables
LEFT RIGHT person ON join_tables.pid=person.id
LEFT JOIN ability ON join_tables.aid=ability.id
WHERE ability.aname !=''sick''

(think it should work and give the following result)

Peter

//Aho


Sjoerd Mulder写道:
Sjoerd Mulder wrote:
大家好,
<我有一个存储人员及其所属团体的数据库。因此我创建了三个表,一个组表,一个人表和联接表。

我有下一个表:

GROUP(id,gname)
1名志愿者2名工人
3名病人

PERSON(id,pname)
1 John
2 Pete
3 Steve

JOIN_PERS_GROUP(id,pname,gname)
1 John,生病
2 John,工作人员
3 Pete,志愿者
4 Steve,生病了查询:
SELECT姓名FROM人
LEFT JOIN join_pers_group使用pname
LEFT JOIN组使用gname
WHERE gname!=''病人''
返回
2 John,工作人员
3 Pete,志愿者

而John也生病了。我如何过滤掉约翰?

提前致谢,
Sjoerd
Hi all,

I have a database storing persons and the groups they belong to. I therefore
created three tables, a group table, person table and join table.

I have for example the next tables:

GROUP(id,gname)
1 volunteer
2 worker
3 sick

PERSON(id,pname)
1 John
2 Pete
3 Steve

JOIN_PERS_GROUP(id, pname, gname)
1 John, sick
2 John, worker
3 Pete, volunteer
4 Steve, sick

Query:
SELECT name FROM person
LEFT JOIN join_pers_group USING pname
LEFT JOIN group USING gname
WHERE gname!=''sick''

Returns
2 John, worker
3 Pete, volunteer

while John is also sick. How can I filter out John?

Thanks in advance,
Sjoerd




但约翰也是工人,所以你在你的名单上得到了工作的约翰。你有...... b $ b要么决定约翰是否生病,他就不能两者兼而有之,只要他在两个团体中出现
,他就会出现在两个人身上;工作者QUOT;和生病的查询。


我认为您的数据库构建错误,我建议:


group(id,gname)

1名志愿者

2名工人

3未知


人(id,pname)

1 John

2 Pete

3 Steve


能力(id,aname)

1工作

2下班

3生病

join_tables(pid,gid,aid)/ * pid和gid是主要的

键 * /

1 2 3

2 1 1

3 3 3


选择人。 pname FROM join_tables

LEFT RIGHT person ON join_tables.pid = person.id

LEFT JOIN能力ON join_tables.aid = ability.id

WHERE ability.aname!=''生病''


(认为它应该有效并给出以下结果)


彼得


// Aho



But John is worker too, so you get the working John on your list. You have
either decide if John is sick or not, he can''t be both and as long as he
appears on both groups, he will appear on both "worker" and "sick" querries.

I think your database is built up wrongly and I would have suggested:

group(id,gname)
1 volunteer
2 worker
3 UNKNOWN

person(id,pname)
1 John
2 Pete
3 Steve

ability(id,aname)
1 working
2 off duty
3 sick

join_tables(pid, gid, aid) /* the combination of pid and gid is the "primary
key" */
1 2 3
2 1 1
3 3 3

SELECT person.pname FROM join_tables
LEFT RIGHT person ON join_tables.pid=person.id
LEFT JOIN ability ON join_tables.aid=ability.id
WHERE ability.aname !=''sick''

(think it should work and give the following result)

Peter

//Aho


好的,这个数据库就是一个例子。关键是我有一个

组织的成员,活跃在所有类别的组中。因此,一个成员可以是许多团体的成员,而另一个成员只是该组织的成员,但

不属于任何团体。


所以也许我的例子选择不是很好,但我必须坚持使用这个

数据库设置。


Sjoerd


" JO AHO" <我们** @ example.net>在消息中写道

news:bq ************* @ ID-130698.news.uni-berlin.de ...
Ok, this database was an example. The point is that I have members of an
organisation, active in all sort of groups. So one member can be member of
many many groups and another member is just member of the organisation, but
not of any group.

So maybe my example was not so well chosen, but I have to stick with this
database setup.

Sjoerd

"J.O. Aho" <us**@example.net> wrote in message
news:bq*************@ID-130698.news.uni-berlin.de...
Sjoerd Mulder写道:
Sjoerd Mulder wrote:
大家好,

我有一个存储人员及其所属团体的数据库。我
因此创建了三个表,一个组表,一个人表和联接表。

我有下一个表:

GROUP(id,gname)
1名志愿者2名工人
3名病人

PERSON(id,pname)
1 John
2 Pete
3 Steve

JOIN_PERS_GROUP(id,pname,gname)
1 John,生病
2 John,工作人员
3 Pete,志愿者
4 Steve,生病了查询:
SELECT姓名FROM人
LEFT JOIN join_pers_group使用pname
LEFT JOIN组使用gname
WHERE gname!=''病人''
返回
2 John,工作人员
3 Pete,志愿者

而John也生病了。我如何过滤掉约翰?

提前致谢,
Sjoerd

但约翰也是工人,所以你把工作的约翰放在你的名单上。你要么决定约翰是否生病,他就不能两者兼而有之,只要他出现在两个群体中,他就会出现在工人身上。和生病
Hi all,

I have a database storing persons and the groups they belong to. I therefore created three tables, a group table, person table and join table.

I have for example the next tables:

GROUP(id,gname)
1 volunteer
2 worker
3 sick

PERSON(id,pname)
1 John
2 Pete
3 Steve

JOIN_PERS_GROUP(id, pname, gname)
1 John, sick
2 John, worker
3 Pete, volunteer
4 Steve, sick

Query:
SELECT name FROM person
LEFT JOIN join_pers_group USING pname
LEFT JOIN group USING gname
WHERE gname!=''sick''

Returns
2 John, worker
3 Pete, volunteer

while John is also sick. How can I filter out John?

Thanks in advance,
Sjoerd
But John is worker too, so you get the working John on your list. You have
either decide if John is sick or not, he can''t be both and as long as he
appears on both groups, he will appear on both "worker" and "sick"



querries。
我认为你的数据库是错误构建的,我建议:

group(id,gname) )
1名志愿者
2名工人
3名未知

人(id,pname)
1 John
2 Pete
3史蒂夫

能力(id,aname)
1工作
2下班
3生病

join_tables(pid,gid,aid) / * pid和gid的组合是
主键 * /
1 2 3
2 1 1
3 3 3

SELECT person.pname FROM join_tables
LEFT RIGHT person ON join_tables.pid = person .ID
LEFT JOIN能力ON join_tables.aid = ability.id
WHERE ability.aname!=''生病''

(认为它应该有效并给出以下结果)

彼得

// Aho


querries.
I think your database is built up wrongly and I would have suggested:

group(id,gname)
1 volunteer
2 worker
3 UNKNOWN

person(id,pname)
1 John
2 Pete
3 Steve

ability(id,aname)
1 working
2 off duty
3 sick

join_tables(pid, gid, aid) /* the combination of pid and gid is the "primary key" */
1 2 3
2 1 1
3 3 3

SELECT person.pname FROM join_tables
LEFT RIGHT person ON join_tables.pid=person.id
LEFT JOIN ability ON join_tables.aid=ability.id
WHERE ability.aname !=''sick''

(think it should work and give the following result)

Peter

//Aho



这篇关于过滤掉约翰的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆