2016-10-28 21 views
0

高さとインチの重さに基づいてBMIフィールドを計算しようとしています。私はあなたがやろうとしたものを見ることができると思い計算された列を使用して別の列を計算しようとしています

SELECT CASE_NUM,HEIGHT_F AS HEIGHT_ft,HEIGHT_I AS HEIGHT_inches,WEIGHT_P AS WEIGHT_lbs,WEIGHT_O AS WEIGHT_oz, 
PRESS_SYST,PRESS_DIAST,HEART_RATE,RESP_RATE,WAIST_CIR,APPROVED_DATE,STAFF_ID, 
S.SORT_NAME AS SERVER_NAME,CAST(PRESS_SYST AS VARCHAR(5)) + '/' + CAST (PRESS_DIAST AS VARCHAR(5)) AS BP, 

HEIGHT_F * 12 + HEIGHT_I 
AS HEIGHT_TOTAL_IN 

FROM (
SELECT 
    (HEIGHT_TOTAL_IN * HEIGHT_TOTAL_IN/WEIGHT_P) * 703 AS BMI 

FROM AZCLCDEV A 
INNER JOIN CDCLIENT C 
ON A.CLIENT_ID = C.ID 
INNER JOIN CAEMP S 
ON A.STAFF_ID = S.ID 

答えて

2

...私は、サブクエリを書きましたが、何かが間違っています。このクエリを試す:

SELECT *, (HEIGHT_TOTAL_IN * HEIGHT_TOTAL_IN/WEIGHT_P) * 703 AS BMI 
FROM (
    SELECT CASE_NUM, HEIGHT_F AS HEIGHT_ft, HEIGHT_I AS HEIGHT_inches, 
      WEIGHT_P AS WEIGHT_lbs,WEIGHT_O AS WEIGHT_oz, 
      PRESS_SYST, PRESS_DIAST, HEART_RATE, RESP_RATE, WAIST_CIR, 
      APPROVED_DATE, STAFF_ID, S.SORT_NAME AS SERVER_NAME, 
      CAST(PRESS_SYST AS VARCHAR(5)) + '/' + CAST (PRESS_DIAST AS VARCHAR(5)) AS BP, 
      HEIGHT_F * 12 + HEIGHT_I AS HEIGHT_TOTAL_IN 
    FROM AZCLCDEV A 
     INNER JOIN CDCLIENT C 
      ON A.CLIENT_ID = C.ID 
     INNER JOIN CAEMP S 
      ON A.STAFF_ID = S.ID 
    ) OrigQuery 
関連する問題