나는이 2 개의 SQL을 결합하여 작성하고 싶습니다. 하나는 다른 결과를 기반으로합니다. 나는 this post을 확인했지만 그 결과가 아닌 것 같습니다. 나는 어떻게 그것을 얻을 수 있 었는가?두 SQL 문을 어떻게 하나로 결합 할 수 있습니까?
먼저 SQL :
SELECT
`potential`.*,
`customer`.`ID` as 'FID_customer'
FROM
`os_potential` as `potential`,
`os_customer` as `customer`
WHERE `potential`.`FID_author` = :randomID
AND `potential`.`converted` = 1
AND `potential`.`street` = `customer`.`street`
AND `potential`.`zip` = `customer`.`zip`
AND `potential`.`city` = `customer`.`city`;
두 번째 SQL은 :
SELECT
sum(`order`.`price_customer`) as 'Summe'
FROM
`os_order` as `order`,
`RESUTS_FROM_PREVIOUS_SQL_STATEMENT` as `results`
WHERE `order`.`FID_status` = 10
AND `results`.`FID_customer` = `order`.`FID_customer`;
I는 SQL + 두 번째 SQL에서 'Summe'에서 모든 것을 얻을 싶습니다.
테이블
1.Potentials :
+----+------------+-----------+--------+-----+------+
| ID | FID_author | converted | street | zip | city |
+----+------------+-----------+--------+-----+------+
2.Customers :
+----+--------+-----+------+
| ID | street | zip | city |
+----+--------+-----+------+
3.Orders : 일
+----+--------------+----------------+
| ID | FID_customer | price_customer |
+----+--------------+----------------+
DB 및 관계의 구조를 알지 못해도 테이블 사이. 그걸 밝힐 수 있니? –
하위 쿼리가 필요할 수 있습니다.테이블처럼 필요한 쿼리의 하위 쿼리로 작동하는 데 필요한 다른 쿼리의 결과 *를 사용하십시오. –
@AndyKorneyev 내 게시물을 편집하고 내 쿼리 아래에 테이블을 표시했습니다. – ksno