显示前端的值

时间:2018-05-31 14:06:03

标签: sql sql-server

如何使用SQL显示与使用SQL的HTML页面中的DB列不同的列值。在这里,我们不希望更新DB中的列值,而只是使用SQL在HTML页面中显示不同的值。

例如: 表1:

void display() {
    glClear(GL_COLOR_BUFFER_BIT);  // Clear colour buffer
    glMatrixMode(GL_MODELVIEW);     // To operateon the model-view matrix
    glLoadIdentity();               // Reset model-view matrix

    glTranslatef(ballX, ballY, 0.0f);   //translate to (xPos, yPos)
    // use triangular segments to form a circle
    glBegin(GL_TRIANGLE_FAN);
    glColor3f(0.0f, 0.0f, 1.0f);    // Biru
    glVertex2f(0.0f, 0.0f);         // center of circle
    int numSegments = 100;
    GLfloat angle;
    for (int i = 0; i <= numSegments; i++) {    // last vertex same as first vertex
        angle = i * 2.0f * PI / numSegments;
        glVertex2f(cos(angle) * ballRadius, sin(angle) * ballRadius);
    }
    glEnd();

    glutSwapBuffers(); // Swap front and back buffers (of double buffered mode)

    // animation control - compute the location for the next refresh
    ballX += xSpeed;
    ballY += ySpeed;
    //Check if the ball exceeds the edges
    if (ballX > ballXMax) {
        ballX = ballXMax;
        xSpeed = -xSpeed;
    }
    else if(ballX < ballXMin) {
        ballX = ballXMin;
        xSpeed = -xSpeed;
    }
    if (ballY > ballYMax) {
        ballY = ballYMax;
        ySpeed = -ySpeed;
    }
    else if (ballY < ballYMin) {
        ballY = ballYMin;
        ySpeed = -ySpeed;
    }
}

现在,我想在HTML中显示ID:A1,名称为&#39; Ramesh&#39;而不是Kumar&#39;使用SQL。怎么做。

1 个答案:

答案 0 :(得分:0)

SQL 中,您可以使用case表达式:

select id, (case when id = 'A1' and name = 'Kumar'  
                 then 'Ramesh' else name 
            end) as Name, 
       Role
from table t;