我正在尝试根据以英寸为单位的身高和以磅为单位的体重来计算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
答案 0 :(得分: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