如何在select语句

时间:2015-11-03 07:51:01

标签: mysql visual-studio mysql-error-1064 mysql-select-db

我想在我的select语句中添加新列

SELECT name,line,style,operation,
7to8am,8to9am,9to10am,10to11am,11to12am,
1to2pm,2to3pm,3to4pm,4to5pm,5to6pm,6to7pm,7to8pm,8to9pm,9to10pm,10to11pm,11to12pm,
sum(7to8am+8to9am+9to10am+10to11am+11to12am+1to2pm
+2to3pm+3to4pm+4to5pm+5to6pm+6to7pm+7to8pm+
8to9pm+9to10pm+10to11pm+11to12pm) as DailyTotal,id from new_hourly GROUP By line

我想添加一个新列,它将显示当天的DailyTotal总和

这是我的sql备份文件http://www.uploadmb.com/dw.php?id=1446536983

请帮帮我!非常感谢你!

1 个答案:

答案 0 :(得分:1)

所以你想要一个额外的列只添加coalesce( sum( case when datee = CURDATE() then 7to8am+8to9am+9to10am+10to11am+11to12am+1to2pm+2to3pm+3to4pm+4to5pm+5to6pm+6to7pm+7to8pm+8to9pm+9to10pm+10to11pm+11to12pm else null end ) ,0) as TodaysTotal 等于当前日期的行吗?

在这种情况下,我会选择表达式:

datee

仅汇总列curdate()SELECT name,line,style,operation, 7to8am,8to9am,9to10am,10to11am,11to12am, 1to2pm,2to3pm,3to4pm,4to5pm,5to6pm,6to7pm,7to8pm,8to9pm,9to10pm,10to11pm,11to12pm, sum(7to8am+8to9am+9to10am+10to11am+11to12am+1to2pm +2to3pm+3to4pm+4to5pm+5to6pm+6to7pm+7to8pm+ 8to9pm+9to10pm+10to11pm+11to12pm) as DailyTotal, coalesce( sum( case when datee = CURDATE() then 7to8am+8to9am+9to10am+10to11am+11to12am+1to2pm+2to3pm+3to4pm+4to5pm+5to6pm+6to7pm+7to8pm+8to9pm+9to10pm+10to11pm+11to12pm else null end ) ,0) as TodaysTotal ,id from new_hourly GROUP By line 的行,如果今天没有行,则返回0。

完整SQL:

var counter = 1;
var interval = setInterval(function () {
    if (counter == 15) {
        clearInterval(interval);
    }
    secondPlay()
    counter++;
}, 1000);