佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 1042|回复: 8

求助一段sql statement....

[复制链接]
发表于 25-4-2006 05:38 AM | 显示全部楼层 |阅读模式
SELECT amount FROM credit_payment_record WHERE CPRID = SELECT CPRID FROM credit_payment_history WHERE Ref_ID = 'ABC'

谁能帮我修改一下上面的sql statement呢?

我要求的只是找出from credit_payment_record 等于CPRID的record(s),但条件是先要找出those record from credit_payment_history which Ref_ID = ABC
回复

使用道具 举报


ADVERTISEMENT

发表于 25-4-2006 09:26 AM | 显示全部楼层
SELECT amount FROM credit_payment_record WHERE CPRID IN (SELECT CPRID FROM credit_payment_history WHERE Ref_ID = 'ABC')

先从
SELECT CPRID FROM credit_payment_history WHERE Ref_ID = 'ABC'
拿出你要得records

再check 你的CRPID有没有在query records





[size=-1]-----------------------------------------
[size=-1]牛奶罐
[size=-1]零点一度 [url]www.dot1degree.com[/url]
[size=-1]从零点开始,寻找你人生第一度的变化!
[size=-1]我的 IT 日记

[ 本帖最后由 milktin 于 14-5-2006 06:43 PM 编辑 ]
回复

使用道具 举报

 楼主| 发表于 25-4-2006 11:03 AM | 显示全部楼层
谢谢! 原来就是这样。。。
回复

使用道具 举报

kengkit 该用户已被删除
发表于 28-4-2006 04:20 PM | 显示全部楼层
SELECT name FROM credit_payment_record WHERE CPRID IN (SELECT cprid
FROM history WHERE Ref_ID = 'ABC' ORDER BY date ASC)

为何显示出来的record, 并没有照着 history talble 的date ascending display 在datagrid...??
回复

使用道具 举报

发表于 28-4-2006 07:42 PM | 显示全部楼层
原帖由 kengkit 于 28-4-2006 04:20 PM 发表
SELECT name FROM credit_payment_record WHERE CPRID IN (SELECT cprid
FROM history WHERE Ref_ID = 'ABC' ORDER BY date ASC)

为何显示出来的record, 并没有照着 history talble 的date ascending displa ...


SELECT name FROM credit_payment_record WHERE CPRID IN (SELECT cprid
FROM history WHERE Ref_ID = 'ABC' ORDER BY date ASC)


那是因为你的 order by 是在 history 的, 改成以下的:

SELECT name FROM credit_payment_record WHERE CPRID IN (SELECT cprid
FROM history WHERE Ref_ID = 'ABC')
ORDER BY date ASC
回复

使用道具 举报

 楼主| 发表于 2-5-2006 04:22 PM | 显示全部楼层
SELECT A.name FROM credit_payment_record as A WHERE A.CPRID IN (SELECT H.cprid
FROM history AS H WHERE H.Ref_ID = 'ABC' ORDER BY H.date ASC ) ORDER BY A.type


它只能sorting by A.Type.. 并不能也同时sorting by H.date
回复

使用道具 举报

Follow Us
anakin81 该用户已被删除
发表于 9-5-2006 04:04 PM | 显示全部楼层
SELECT CPRID FROM credit_payment_history
WHERE Ref_ID = 'ABC'
ORDER BY a.type ASC;
回复

使用道具 举报

 楼主| 发表于 9-5-2006 11:10 PM | 显示全部楼层
原帖由 anakin81 于 9-5-2006 04:04 PM 发表
SELECT CPRID FROM credit_payment_history
WHERE Ref_ID = 'ABC'
ORDER BY a.type ASC;


可以post完整的sql statement 吗?
回复

使用道具 举报


ADVERTISEMENT

发表于 10-5-2006 09:02 PM | 显示全部楼层
原帖由 counterking 于 2-5-2006 04:22 PM 发表
SELECT A.name FROM credit_payment_record as A WHERE A.CPRID IN (SELECT H.cprid
FROM history AS H WHERE H.Ref_ID = 'ABC' ORDER BY H.date ASC ) ORDER BY A.type


它只能sorting by A.Type.. 并不能也 ...


大概是這樣

SELECT A.name, B.date FROM credit_payment_record A left join
history B on A.CPRID = B.cprid
WHERE A.CPRID IN (SELECT H.cprid
FROM history H WHERE H.Ref_ID = 'ABC' ) ORDER BY A.type, B.date

不過, 以上的 FIELD NAME 使用許多 KEYWORD, 容易讓人混亂
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 11-11-2024 09:20 PM , Processed in 0.533496 second(s), 26 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表