instruction: Provide me the number of patients who stayed in the hospital for more than 27 days that had a magnesium lab test.
response: SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN lab ON demographic.hadm_id = lab.hadm_id WHERE demographic.days_stay > "27" AND lab.label = "Magnesium"