1 테이블에서 중앙값을 계산하는 방법을 알고 있지만 6 테이블에서 가격을 비교하려고합니다. 지금까지 내 코드를 도울 수 있습니까?6 개 테이블의 중앙값 얻기
select avg(price) as median from
(select row_id, price from (
(select @counter:[email protected]+1 as row_id, t1.priceInt as price
from Table1 t1, (select @counter:=0) tx1
)
union all (select @counter:[email protected]+1 as row_id, t2.priceInt as price
from Table2 t2, (select @counter:=0) tx2
)
union all (select @counter:[email protected]+1 as row_id, t3.priceInt as price
from Table3 t3, (select @counter:=0) tx3
)
union all (select @counter:[email protected]+1 as row_id, t4.priceInt as price
from Table4 t4, (select @counter:=0) tx4
)
union all (select @counter:[email protected]+1 as row_id, t5.priceInt as price
from Table5 t5, (select @counter:=0) tx5
)
union all (select @counter:[email protected]+1 as row_id, t6.priceInt as price
from Table6 t6, (select @counter:=0) tx6
)
) xx order by price) o1 join
(
select sum(x) AS total_rows from
(
select count(*) x from Table1 union all select count(*) x from
Table2
union all select count(*) x from Table3 union all select count(*) x
from Table4
union all select count(*) x from Table5 union all (select count(*) x
from Table6
)
) o2 where o1.row_id in (floor((o2.total_rows + 1)/2),
floor((o2.total_rows + 2)/2)))
o1.row_id가 인식되지 않습니다.
다음은 표 1의 예입니다. 각 표에는 동일한 열이 있습니다!
*** 편집
원하는 결과 : 250, 275, 300, 400, 500은 내가 원하는 300K (2 개 중간 번호가있는 경우 숫자가 주문해야하고 주 평균은 2 개의 숫자로 이루어져야합니다.)
나는 지난 24 시간 동안 게시 된 질문과 거의 동일한 질문을 본 적이 있음을 맹세 할 수 있습니다. 전에 물어 본 적이 있니? –
이것은 정상적으로 처리되지 않은 스키마처럼 들립니다. 왜 당신의 가격은 6 개의 테이블에 흩어져 있습니까? – duffymo