$s1="SELECT a ,c from sub where a='1'";
$s2="SELECT b ,c from sub where b='1'";
要如何在PHP語言中取出$s1和$s2的'c' 並相減
或者是如何在一個指令下做出兩個指令相減
INSERT INTO sub
VALUES (1,2,55),(1,3,66),(1,4,77),(2,1,88),(2,3,99),(2,4,22),(3,1,33),(3,2,44),(3,4,55),(4,1,66),(4,2,77),(4,3,88);
我試過
SELECT ((SELECT c from sub where a='1')-(SELECT c from sub where b='1')) LIMIT 0, 25
MySQL 的回應是
#1242 - Subquery returns more than 1 row
自己在修改運用..
SELECT (s1.c - s2.c) AS c,
s1.a AS 's1-a',
s1.b AS 's1-b',
s2.a AS 's2-a',
s2.b AS 's2-b'
FROM sub s1 , (
SELECT * FROM sub WHERE b = 1 #查數值不要加引號
) s2
WHERE s1.a = 1; #查數值不要加引號
$s3=SELECT ((SELECT c from sub where a='1')-(SELECT c from sub where b='1'));