Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MySql查询-显示状态_Mysql - Fatal编程技术网

MySql查询-显示状态

MySql查询-显示状态,mysql,Mysql,我有学生表和学生课程表。我正在计算学生完成认证课程的百分比。我没有显示百分比,而是要求显示以下状态: Percent Complete = 0; Training Status would be Assigned; Certification Status-N/A Percent Complete = 33;Training Status would be In-Progress; Certification Status-Pending Percent Complete = 66;Traini

我有学生表和学生课程表。我正在计算学生完成认证课程的百分比。我没有显示百分比,而是要求显示以下状态:

Percent Complete = 0; Training Status would be Assigned; Certification
Status-N/A Percent Complete = 33;Training Status would be In-Progress;
Certification Status-Pending Percent Complete = 66;Training Status
would be Complete; Certification Status-In-Progress
我如何计算百分比并显示上面的详细信息而不是百分比

SELECT CONCAT(Student.LastName,', ', Student.FirstName) AS "FULL NAME",        
    studentcourse.CourseID as "COURSE", 
    studentcourse.Status AS "TRAINING STATUS", studentcourse.PercentComplete,
    studentcourse.status as 'CERTIFICATION STATUS' 
FROM studentcourse, student, Course
where Student.OrgID='DECC'
    AND student.studentID=studentcourse.StudentID
    AND Student.IsActiveFlag='1'
    AND Course.CourseID=StudentCourse.CourseID
示例数据:正在删除百分比列

FULL NAME         COURSE                 TRAINING STATUS  %Complete CERT STATUS
Adkins, Willa         DECC_PER              not attempted   0   not attempted
Adkins, Willa         LMS_Training_DECC     not attempted   0   not attempted
Akers, Dianne         DECC_PER              not attempted   0   not attempted
Akers, Dianne         LMS_Training_DECC     not attempted   0   not attempted
Alexander, Richard    DECC_PER              not attempted   0   not attempted
Alexander, Richard    LMS_Training_DECC     not attempted   0   not attempted
Altamirando, Ardella  8570_Pending_CE_NE        completed   100 completed
Altamirando, Ardella  8570_Pending_IA           completed   100 completed

正在尝试使用用例,但出现语法错误。

此查询假设百分比级别如下:

  • 0%:培训状态
    已分配
    ;证书状态
    N/A
  • >0%至33%:培训状态
    正在进行中
    ;证书状态
    Pending
  • >33%和高达66%:培训状态
    完成
    ;证书状态
    正在进行中
  • >66%:
如果这个假设是错误的,您需要调整下面
案例中的数字

SELECT
  CONCAT(Student.LastName,', ', Student.FirstName) AS "FULL NAME",        
  studentcourse.CourseID as "COURSE", 
  studentcourse.PercentComplete,
  CASE
    WHEN studentcourse.PercentComplete = 0 THEN 'Assigned'
    WHEN studentcourse.PercentComplete <= 33 THEN 'In-Progress'
    WHEN studentcourse.PercentComplete <= 66 THEN 'Complete'
    ELSE 'whatever comes next'
    END AS "TRAINING STATUS",
  CASE
    WHEN studentcourse.PercentComplete = 0 THEN 'N/A'
    WHEN studentcourse.PercentComplete <= 33 THEN 'Pending'
    WHEN studentcourse.PercentComplete <= 66 THEN 'In-Progress'
    ELSE 'whatever comes next'
    END AS "CERTIFICATION STATUS"
FROM studentcourse, student, Course
WHERE Student.OrgID='DECC'
  AND student.studentID=studentcourse.StudentID
  AND Student.IsActiveFlag='1'
  AND Course.CourseID=StudentCourse.CourseID

哇!我知道我必须使用用例,但有语法错误。熟悉Oracle SqlPlus而不是MySql。这是现场,我感谢你!
SELECT
  . . . same as above
FROM studentcourse
INNER JOIN student ON studentcourse.StudentID = student.studentID
INNER JOIN Course ON StudentCourse.CourseID = Course.CourseID
WHERE Student.OrgID='DECC'
  AND Student.IsActiveFlag='1'