Показать сообщение отдельно

  #8  
Старый 04.05.2010, 17:34
OdaN
Участник форума
Регистрация: 04.03.2006
Сообщений: 159
С нами: 10625303

Репутация: 39
По умолчанию

Помогите плз с оптимизацией:
есть запрос:
PHP код:
select w.city,r.name as cityname,w.sunrise,w.sunset,w.date,w.dpart,w.type,w.winddir,w.windspd,w.pressure,w.dampness,w.obstime,w.wcolor,w.temp,w.ncolor,w.ntemp,w.tomcolor,w.tomtemp,r.offset,
if (
w.sunrise date_format(date_sub(now(), interval (14400-(r.offset)) second),'%H:%i:%s')
and 
w.sunset date_format(date_sub(now(), interval (14400-(r.offset)) second),'%H:%i:%s'),
timediff(w.sunset,date_format(date_sub(now(), interval (14400-(r.offset)) second),'%H:%i:%s')),
if (
date_format(date_sub(now(), interval (14400-(r.offset)) second),'%H:%i:%s') > '00:00:00' and
date_format(date_sub(now(), interval (14400-(r.offset)) second),'%H:%i:%s') < w.sunrise,
timediff(w.sunrise,date_format(date_sub(now(), interval (14400-(r.offset)) second),'%H:%i:%s')),
addtime(timediff('23:59:59',date_format(date_sub(now(), interval (14400-(r.offset)) second),'%H:%i:%s')),w.sunrise))
) as `
change`,
if (
w.sunrise date_format(date_sub(now(), interval (14400-(r.offset)) second),'%H:%i:%s')
and 
w.sunset date_format(date_sub(now(), interval (14400-(r.offset)) second),'%H:%i:%s'),1,0) as lite,
date_sub(now(), interval (14400-(r.offset)) second) as `localtime`
from weather w left join regions r on w.city=r.city where w.city $city order by w.id desc limit 1 
Там часто используется выражения типа
Код:
date_format(date_sub(now(), interval (14400-(r.offset)) second),'%H:%i:%s'))
для получения локального времени. как можно все это загнать в переменную, и в принципе уменьшить запрос, хотя-бы для экономии трафика?

Используется тут: http://export.selaz.org/weather/


Структура таблиц:
Код:
CREATE TABLE IF NOT EXISTS `regions` (
  `id` int(11) NOT NULL auto_increment,
  `yanid` int(11) NOT NULL,
  `city` int(11) NOT NULL,
  `name` varchar(64) NOT NULL,
  `offset` int(11) NOT NULL,
  `weather` tinyint(1) default NULL,
  PRIMARY KEY  (`id`),
  UNIQUE KEY `yanid` (`yanid`),
  UNIQUE KEY `city` (`city`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8;


CREATE TABLE IF NOT EXISTS `weather` (
  `id` int(11) NOT NULL auto_increment,
  `city` int(11) NOT NULL,
  `sunrise` time NOT NULL,
  `sunset` time NOT NULL,
  `date` date NOT NULL,
  `dpart` tinyint(4) NOT NULL,
  `type` varchar(32) NOT NULL,
  `windspd` tinyint(4) NOT NULL,
  `winddir` varchar(8) NOT NULL,
  `pressure` smallint(6) NOT NULL,
  `dampness` tinyint(4) NOT NULL,
  `obstime` time NOT NULL,
  `temp` tinyint(11) NOT NULL,
  `wcolor` varchar(6) NOT NULL,
  `ncolor` varchar(6) NOT NULL,
  `ntemp` tinyint(4) NOT NULL,
  `tomcolor` varchar(6) NOT NULL,
  `tomtemp` tinyint(4) NOT NULL,
  PRIMARY KEY  (`id`),
  UNIQUE KEY `city` (`city`,`date`,`obstime`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8;

Последний раз редактировалось OdaN; 04.05.2010 в 17:39..
 
Ответить с цитированием