是否可以根据 where 子句更改虚拟列值?
我有这张桌子:
[computername] [computerlocation] [starttime] [endtime]
computer, siteA, 1457537657, 1457532657
computer2, siteB, 1457547657, 1457546657
computer3, siteB, 1457237657, 14575237657
我想看看在给定站点和给定时间范围内有多少台计算机,我目前使用的查询是:
select count(*), computerlocation
from table
where site like "site%"
and starttime <= "1457532657" and endtime >= "1457532657"
group by computerlocation
但是,目前我必须运行此查询数百次才能创建一个图表,该图表显示一段时间内有多少台计算机。
有没有可能做这样的事情:
select count(*), computerlocation, "null" as time
from table
where site like "site%"
and ( (starttime <= "1457532657" and endtime >= "1457532657" as time="timeA")
OR (starttime <= "1457532357" and endtime >= "1457532357" as time="timeB")
OR (starttime <= "1457532651" and endtime >= "1457532651" as time="timeC")
)
group by time, computerlocation