我正在尝试根据第二张表中的数据排序,以根据第三张表中的ID来显示在一个列表中。
表3包含其他2个表的ID。
e_allocation table
------------------
eid, sid, iid
5, 1234, NULL
5, NULL, 1234
表1和2是相似数据的表。
i_status table
--------------
iid, status
1234, Complete
1235, Complete
1236, Not Complete
s_status table
--------------
sid, status
1234, Complete
1235, Not Complete
1237, Not Complete
objCon.Execute ("SELECT a.sid, a.iid, b.status AS istats, c.status AS sstats
FROM e_allocation a LEFT JOIN i_status b ON a.iid=b.iid LEFT JOIN s_status c
ON a.sid=c.sid WHERE a.eid = '5' ORDER BY b.status Desc, c.status Desc")
因此,目前我可以从数据库中获取数据,但是显然它首先对表b进行排序,然后对c进行排序。我需要这些命令加入。
当前返回(Table=I or S, Record ID=1234, Status = Complete or Not Complete)
:
I:1234:Complete
I:1235:Complete
I:1236:Not complete
S:1234:Complete
S:1235:Not Complete
S:1237:Not Complete
我正在尝试获取:
I:1234:Complete
S:1234:Complete
I:1235:Complete
S:1235:Not Complete
I:1236:Not complete
S:1237:Not Complete
while not objDb.EOF
sid = objDb("id")
iid = objDb("iid")
if sid <>"" then datlst = datlst &"S:"& sid &":"&objDb("sstats")&",<BR>"
if iid <>"" then datlst = datlst &"I:"& iid &":"&objDb("istats")&",<BR>"
objDb.MoveNext
Wend
response.write datlst
任何朝着正确方向的指针都值得赞赏吗? 谢谢
答案 0 :(得分:0)
这是我的尝试。
create table e_allocation (eid int, sid int, iid int);
insert into e_allocation select 5, 1234, NULL;
insert into e_allocation select 5, NULL, 1234;
insert into e_allocation select 5, 1235, NULL;
insert into e_allocation select 5, NULL, 1235;
insert into e_allocation select 5, 1236, NULL;
insert into e_allocation select 5, NULL, 1236;
create table i_status (iid int, status varchar(25));
insert into i_status select 1234, 'Complete';
insert into i_status select 1235, 'Complete';
insert into i_status select 1236, 'Not Complete';
create table s_status (sid int, status varchar(25));
insert into s_status select 1234, 'Complete';
insert into s_status select 1235, 'Not Complete';
insert into s_status select 1237, 'Not Complete';
SELECT
case when a.sid is null then 'I' else 'S' end as iors,
ifnull(a.sid,a.iid) as id,
ifnull(b.status,c.status) as status
FROM e_allocation a LEFT JOIN i_status b ON a.iid=b.iid LEFT JOIN s_status c
ON a.sid=c.sid
WHERE a.eid = '5' and (b.status is not null or c.status is not null)
ORDER BY id, iors
下次请提供CREATE TABLE等语句,这样我们就不必键入它们。