0

表station_tbl:

station_name   |  fare_adult |  fare_child |  fare_OKU |  type |    stationid

New City            2.00         1.00         1.00       0            19900
Old Village         2.00         1.00         1.00       0            54900
Old City            5.00         2.50         2.50       1            23100
New Castle          1.00         0.50         0.50       1            22900
Adult                                                    2              0
Child                                                    2              1
OKU                                                      2              2
Single                                                   3              0
Return                                                   3              1

我的查询:显示票务信息

SELECT
    A.ticketid,
    B.station_name AS stationid,
    c.station_name AS destination,
    CONVERT(VARCHAR(5), GETDATE(), 108) AS TIME,
    CONVERT(VARCHAR(12), GETDATE(), 103) AS Date,
    D.station_name AS ticket_type,
    e.station_name AS journey_type,
    amount,
    issuedby
FROM ticketcollections AS A, 
    station_tbl AS B, 
    station_tbl AS c, 
    station_tbl AS D, 
    station_tbl AS e
WHERE A.ticketidparent = '" + Request("ParentId") + "'
    AND A.stationid = B.stationid
    AND B.type = 0
    AND A.destination = c.stationid
    AND c.type = 0
    AND A.ticket_type = D.stationid
    AND D.type = 4
    AND A.journey_type = e.stationid
    AND e.type = 3

我已将所有数据合并到一张表中。

该表仅用于存储站名和车票类型的名称。

因为在表中ticketcollections只是存储code (1, 2, 3, 4)。所以当我想打印票时,我会参考这个station_tbl来显示命名。

如果此查询会使查询太慢,请帮助我。

在我的电脑上速度很快,但在用户电脑上速度很慢。

我只提到了 2 张桌子。

4

2 回答 2

0

尝试这个:

SELECT
    A.ticketid,
    B.station_name AS stationid,
    B.station_name AS destination,
    CONVERT(VARCHAR(5), GETDATE(), 108) AS TIME,
    CONVERT(VARCHAR(12), GETDATE(), 103) AS Date,
    B.station_name AS ticket_type,
    B.station_name AS journey_type,
    amount,
    issuedby
FROM ticketcollections A
    station_tbl AS B,
WHERE A.ticketidparent = '" + Request("ParentId") + "'
    AND A.stationid = B.stationid
    AND B.type in(0,4,3)
于 2013-07-10T05:49:47.113 回答
0

你的桌子上有索引吗?我建议至少将它们放在 ticketcollections 和 station_tbl 的 stationId 和 station_tbl 类型上。

于 2013-07-10T05:50:38.210 回答