0

I would like to know if it is possible to combine two statements into a single one in SQLite.

The first statement is the following:

SELECT MAX(goodput_mbps), packetsize_bytes 
FROM data 
WHERE src = "A" AND dst = "B" 
GROUP BY packetsize_bytes

which produces somthing like:

(1.065251641628522, 32)
(2.023058064838313, 64)
(3.9937457226166333, 128)
(7.13931248161879, 256)
(9.732371794078158, 384)
(12.030082350641777, 512)
(14.941748420411137, 640)
(16.768300606617814, 768)
(19.55032187231529, 1028)
(21.54109687187735, 1280)
(23.025071751003825, 1460)
(15.871752691948677, 1534)
(17.309115863006014, 1788)
(18.40483524961694, 2048)

For each entry I then run another SQL query using as parameters for the WHERE clause the first and the second entry of each record, for example for the first entry of the previous result set I would run:

SELECT MAX(median)-MIN(median) / MAX(bitrate_mbps)-MIN(bitrate_mbps), packetsize_bytes 
FROM data 
WHERE src = "A" and dst = "B" and packetsize_bytes = 32 and bitrate_mbps < 1.12 
ORDER BY bitrate_mbps ASC 

which produces something like:

(0.035000000000000225, 32)

Basically I would like to have a single query that produces something like:

(x, 32)
(x, 64)
(x, 128)
(x, 256)
(x, 384)
(x, 512)
(x, 640)
(x, 768)
(x, 1028)
(x, 1280)
(x, 1460)
(x, 1534)
(x, 1788)
(x, 2048)

Is this possible in SQLite? I know that there is the WHERE IN clause but it seem to accept a single parameter.

4

4 回答 4

0

您没有指定“组合”,但如果您只想获得两个查询的结果,您可以将它们与UNION ALL组合:

SELECT MAX(goodput_mbps), packetsize_bytes
FROM data
WHERE src = 'A' AND dst = 'B'
GROUP BY packetsize_bytes

UNION ALL

SELECT MAX(median)-MIN(median) / MAX(bitrate_mbps)-MIN(bitrate_mbps),
       packetsize_bytes
FROM data
WHERE src = 'A' AND dst = 'B'
  AND packetsize_bytes = 32 AND bitrate_mbps < 1.12

ORDER BY bitrate_mbps ASC
于 2013-07-30T09:09:14.567 回答
0
SELECT MAX(median)-MIN(median) / MAX(bitrate_mbps)-MIN(bitrate_mbps), 
       packetsize_bytes 
FROM 
    (SELECT MAX(goodput_mbps) , packetsize_bytes 
    FROM data 
    WHERE src = "A" AND dst = "B" 
    GROUP BY packetsize_bytes) 

WHERE packetsize_bytes = 32 and bitrate_mbps < 1.12 
ORDER BY bitrate_mbps ASC 
于 2013-07-30T08:49:34.360 回答
0
SELECT MAX(d1.median)-MIN(d1.median) / MAX(d1.bitrate_mbps)-MIN(d1.bitrate_mbps), d2.packetsize_bytes 
FROM data d1, (SELECT MAX(goodput_mbps), packetsize_bytes FROM data WHERE src = "A" AND dst = "B" GROUP BY packetsize_bytes) d2  
WHERE d1.src = "A" and d1.dst = "B" and d1.packetsize_bytes = d2.packetsize_bytes and d1.bitrate_mbps < "d2.MAX(goodput_mbps)"  
GROUP BY d2.packetsize_bytes
ORDER BY d2.packetsize_bytes ASC
于 2013-08-03T09:13:58.587 回答
-2

不,你不能,因为 SQLite 本身不支持分析函数也不支持 pl/sql。

于 2013-07-30T09:09:49.430 回答