Redian新闻
>
SQL 查询已经解决.谢谢Modeler,mirthc,cheungche
avatar
SQL 查询已经解决.谢谢Modeler,mirthc,cheungche# Database - 数据库
c*n
1
本文是“【双节征文】如水中月,如镜中花---牌例一则”的后续
如果还没看过原文,请看这里
http://www.mitbbs.com/article_t/WmGame/31143119.html
如果看过了,并选择出小王,请接着看,否则请离开
你出小王上手,下一手出方A
庄出方6,庄下出方5,帮庄出方6,如果你下一手出红A,请接着看,否则请离开
(你方已经得了5分)
你出红A,庄出红4,庄下出红10,帮庄长考,出红7
(你方已经得了15分)
如果你下一手出方44,请接着看,否则请离开
你出方44,庄出方77,庄下出方JJ,帮庄出方9,3
下一轮,
庄下出方88,帮庄出方Q,5,你出方K,9(唯一出法,只剩这两张),庄出A,Q
(你方已经得了30分)
下一轮,庄下长考,出花33,帮庄长考,出花10,6,你出花6,4,庄出花55
下一轮,庄出红K,庄下出红4,帮庄出红7,你出什么?
avatar
w*g
2
两个table, table1, table2 . 每个table各有两列A 和 B. 。 如何从table 1 选择出,
table1.A 和table2.A相等,在这个条件下,B不等的那些行。
想选择出如下的行
A B
835448 3
835448 4
835448 5
835449 2
835449 3
table1 的数据
A B
835448 0
835448 1
835448 2
835448 3
835448 4
835448 5
835449 0
835449 1
835449 2
835449 3
table2的数据
A B
835448 0
835448 1
835448 2
835449 0
835449 1
我写的语句
select distinct table1.A, table1.B
from table1, table2
where table1.A
avatar
s*0
3
这还用问,当然是小主46.
avatar
a*t
4
double check your query
select distinct table1.A, table1.B --you really mean to pull distinct only?
from table1, table2
where table1.A=RXs.table2.A --what is RXs?
AND table2.B != table2.B --you mean table1.B <> table2.B
order by A --you didn't get an error with this? need to provide table name
avatar
c*n
5
那我接着写下一轮

【在 s*******0 的大作中提到】
: 这还用问,当然是小主46.
avatar
w*g
6
敲错了一个东西,
这个query是可以运行的,
但是结果不是我想要的。
请问应该如何些query的我想要的结果呢?
谢谢

【在 a*******t 的大作中提到】
: double check your query
: select distinct table1.A, table1.B --you really mean to pull distinct only?
: from table1, table2
: where table1.A=RXs.table2.A --what is RXs?
: AND table2.B != table2.B --you mean table1.B <> table2.B
: order by A --you didn't get an error with this? need to provide table name

avatar
s*0
7
红6
看来庄有红A,留着小屁对好了。毕竟K还挺大的。卡着庄就行,对家有大红对子就认命
吧。这个K就打算不从对家大对子跑了。
avatar
a*t
8
select table1.*
from table1, table2
where table1.A = table2.B
and table1.B <> table2.B
you can try it, not sure if it'll work
and it's recommanded to use "join" operator instead of implied join by using "where" causes

【在 w*********g 的大作中提到】
: 敲错了一个东西,
: 这个query是可以运行的,
: 但是结果不是我想要的。
: 请问应该如何些query的我想要的结果呢?
: 谢谢

avatar
w*g
10
还是错误的,我很崩溃。
table1 的A列的数据,存在于 和table2 的A列,
但是 table1 中的B列有一些数据 不 存在于 table 2的B列,
想把table1和table2 中 A列相同,但是B列不存在的那些行选出来。
请看我的原文描述。
avatar
m*2
11
select t1.* from table1 t1
left join table2 t2
on t1.a = t2.a
where table2.a is null

【在 w*********g 的大作中提到】
: 还是错误的,我很崩溃。
: table1 的A列的数据,存在于 和table2 的A列,
: 但是 table1 中的B列有一些数据 不 存在于 table 2的B列,
: 想把table1和table2 中 A列相同,但是B列不存在的那些行选出来。
: 请看我的原文描述。

avatar
m*2
12
没有看到这个。
这样试试:
select * from table1 t1
where t1.a in
(select t2.a from table2 t2)
and t1.b not in
(select t2.b from table2 t2)

【在 w*********g 的大作中提到】
: 还是错误的,我很崩溃。
: table1 的A列的数据,存在于 和table2 的A列,
: 但是 table1 中的B列有一些数据 不 存在于 table 2的B列,
: 想把table1和table2 中 A列相同,但是B列不存在的那些行选出来。
: 请看我的原文描述。

avatar
w*g
13
不行啊,
还是一样的结果。
没有选出A列中存在,但B列不存的数。

【在 m**********2 的大作中提到】
: 没有看到这个。
: 这样试试:
: select * from table1 t1
: where t1.a in
: (select t2.a from table2 t2)
: and t1.b not in
: (select t2.b from table2 t2)

avatar
M*r
14
选出table1.A=table2.A and table1.B=table2.B 的rows, 然后从table1里面减去这些
rows。

出,

【在 w*********g 的大作中提到】
: 两个table, table1, table2 . 每个table各有两列A 和 B. 。 如何从table 1 选择出,
: table1.A 和table2.A相等,在这个条件下,B不等的那些行。
: 想选择出如下的行
: A B
: 835448 3
: 835448 4
: 835448 5
: 835449 2
: 835449 3
: table1 的数据

avatar
w*g
15
query 如何写?多谢。

【在 M*****r 的大作中提到】
: 选出table1.A=table2.A and table1.B=table2.B 的rows, 然后从table1里面减去这些
: rows。
:
: 出,

avatar
M*r
16
select * from tbl1 except (select tbl1.* from tbl1, tbl2 where tbl1.A=tbl2.A
and tbl1.B=tbl2.B)
上面这个query基于一些假设,也许只适用于你给的例子

【在 M*****r 的大作中提到】
: 选出table1.A=table2.A and table1.B=table2.B 的rows, 然后从table1里面减去这些
: rows。
:
: 出,

avatar
m*y
17
SQL SERVER 2000:
SELECT t1.A, t1.B
FROM table1 t1
LEFT OUTER JOIN table2 t3 ON t1.A=t3.A AND t1.B=t3.B
WHERE t3.A IS NULL
AND EXISTS (SELECT 1 FROM table2 t2 WHERE t2.A=t1.A)
2005:
SELECT A, B
FROM
(
SELECT A,B FROM table1 t1
EXCEPT
SELECT A,B FROM table2 t2
) t3
WHERE EXISTS (SELECT 1 FROM table2 WHERE t3.A=table2.A)
avatar
b*o
18
Select * from t1 where concat(A,'_',B) not in
(Select distinct concat(A,'_',B) from t2)
avatar
c*e
19
你这个query有问题,
table1:
A B
835448 0
table2:
A B
835448 0
835448 1
这里table1和table2第二个record满足你的条件
但是实际上table2里面有table1里面的record
记住在A相等的情况下,table2里面只要有一条记录不等,
table1里面那条就会被pull进来
一般你可以用minus或者outer join + where ... is null

出,

【在 w*********g 的大作中提到】
: 两个table, table1, table2 . 每个table各有两列A 和 B. 。 如何从table 1 选择出,
: table1.A 和table2.A相等,在这个条件下,B不等的那些行。
: 想选择出如下的行
: A B
: 835448 3
: 835448 4
: 835448 5
: 835449 2
: 835449 3
: table1 的数据

avatar
c*e
20
具体query;
select A, B from table1
minus
select A, B from table2
或者
select table1.A, table1.B
from table1
left outer join table2
on table1.A = table2.A
and table1.B = table2.B
where table2.B is null ;

【在 c*******e 的大作中提到】
: 你这个query有问题,
: table1:
: A B
: 835448 0
: table2:
: A B
: 835448 0
: 835448 1
: 这里table1和table2第二个record满足你的条件
: 但是实际上table2里面有table1里面的record

avatar
w*g
21
谢谢 Modeler,mirthcyy, 还有cheungche, 问题已经解决,谢谢大家热心的指导,太
感谢了。
avatar
r*y
22
试试这个
select t1.* from table1 t1
where
t1.a in (select t2.a from table2 t2)
and not exists (
selct t2.a from table t2
where t1.a = t2.a and
t1.b = t2.b
)
avatar
w*g
23
你好,你的这个query可以给小弟解释一下吗,谢谢。
我没读懂

【在 m******y 的大作中提到】
: SQL SERVER 2000:
: SELECT t1.A, t1.B
: FROM table1 t1
: LEFT OUTER JOIN table2 t3 ON t1.A=t3.A AND t1.B=t3.B
: WHERE t3.A IS NULL
: AND EXISTS (SELECT 1 FROM table2 t2 WHERE t2.A=t1.A)
: 2005:
: SELECT A, B
: FROM
: (

avatar
m*y
24
SELECT t1.A, t1.B
FROM table1 t1
LEFT OUTER JOIN table2 t3 ON t1.A=t3.A AND t1.B=t3.B
WHERE t3.A IS NULL
AND EXISTS (SELECT 1 FROM table2 t2 WHERE t2.A=t1.A)
LEFT OUTER JOIN plus NULL criteria 就等于找table1里面与table2 A和B value有不
相同的records. 这个同2005的except是一样的。
Exists 那部分找table1里面A value也在table2里面的records.
两个合起来就是你要的了。
avatar
w*g
25
谢谢你,现在很明白了。请问哪一个教材比较好的讲了复合 t-sql 的操作呢?
我想系统的学习一下,感觉还是很多要学习

【在 m******y 的大作中提到】
: SELECT t1.A, t1.B
: FROM table1 t1
: LEFT OUTER JOIN table2 t3 ON t1.A=t3.A AND t1.B=t3.B
: WHERE t3.A IS NULL
: AND EXISTS (SELECT 1 FROM table2 t2 WHERE t2.A=t1.A)
: LEFT OUTER JOIN plus NULL criteria 就等于找table1里面与table2 A和B value有不
: 相同的records. 这个同2005的except是一样的。
: Exists 那部分找table1里面A value也在table2里面的records.
: 两个合起来就是你要的了。

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。