이렇게 내가 끝내고 내가 원하는 방식으로 데이터를 제공하는 것으로 보입니다. 그때이 절차를 설정
USE `glpi`;
DROP procedure IF EXISTS `Daily_Ticket_Stats`;
DELIMITER $$
USE `glpi`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `Daily_Ticket_Stats`()
BEGIN
declare todayd date;
## Declaring the variable for the daterun column ##
declare todayt time;
## Declaring the variable for the timerun column ##
declare totalt int(11);
## Declaring the variable for totaltickets column ##
declare vlow int (11);
## Declaring the variable for verylow column ##
declare low int(11);
## Declaring the variable for low column ##
declare med int(11);
## Declaring the variable for med column ##
declare high int (11);
## Declaring the variable for high column ##
declare vhigh int(11);
## Declaring the variable for veryhigh column ##
set todayd = CURDATE();
## Set date to today ##
set todayt = CURTIME();
## Set time to now ##
set totalt = (SELECT COUNT(*) as ttickets
FROM glpi.glpi_tickets
WHERE day(date)=day(NOW()));
## This has set the total for the total tickets variable ##
set vlow = (SELECT COUNT(*) as vltickets
FROM glpi.glpi_tickets
WHERE day(date)=day(NOW())
AND urgency = '1');
## This has set the total for the very low urgency tickets variable ##
set low = (SELECT COUNT(*) as ltickets
FROM glpi.glpi_tickets
WHERE day(date)=day(NOW())
AND urgency = '2');
## This has set the total for the low urgency tickets variable ##
set med = (SELECT COUNT(*) as mtickets
FROM glpi.glpi_tickets
WHERE day(date)=day(NOW())
AND urgency = '3');
## This has set the total for the medium urgency tickets variable ##
set high = (SELECT COUNT(*) as htickets
FROM glpi.glpi_tickets
WHERE day(date)=day(NOW())
AND urgency = '4');
## This has set the total for the high urgency tickets variable ##
set vhigh = (SELECT COUNT(*) as vhtickets
FROM glpi.glpi_tickets
WHERE day(date)=day(NOW())
AND urgency = '5');
IF EXISTS(
SELECT *
FROM glpi.glpi_plugin_ns_ticketstats
WHERE daterun = CURDATE())
THEN
BEGIN
UPDATE glpi.glpi_plugin_ns_ticketstats
SET
timerun = CURTIME(),
totaltickets = totalt,
verylow = vlow,
low = low,
med = med,
high = high,
veryhigh = vhigh
WHERE
daterun = CURDATE();
END;
ELSE
INSERT INTO glpi.glpi_plugin_ns_ticketstats VALUES (NULL,todayd,todayt,totalt,vlow,low,med,high,vhigh);
END IF;
END
#$$
DELIMITER ;
:
CREATE TABLE glpi_plugin_ns_ticketstats
(
id INT(11),
daterun date,
timerun time,
totaltickets INT(11),
verylow INT(11),
low INT(11),
med INT(11),
high INT(11),
veryhigh INT(11));
그럼 내가 수집하고 데이터를 채우기 위해 저장 프로 시저를 구축 : 모든
먼저 나는에 데이터를 저장하기 위해 새 테이블을 생성 매일 매니저가 매시간 실행하기 때문에 관리자가 당일에 참조하기를 원한다면 (나는 이것을 mysql 서버 터미널에 직접 입력했다.)
29 분은 내가 얻을 수있는 시간에 가까운 곳에서 달리기를 원했기 때문입니다.
# id, daterun, timerun, totaltickets, verylow, low, med, high, veryhigh
'1', '2016-06-01', '23:00:00', '0', '0', '0', '0', '0', '0'
'2', '2016-06-02', '23:00:00', '0', '0', '0', '0', '0', '0'
'3', '2016-06-03', '23:00:00', '0', '0', '0', '0', '0', '0'
'4', '2016-06-04', '23:00:00', '0', '0', '0', '0', '0', '0'
'5', '2016-06-05', '23:00:00', '0', '0', '0', '0', '0', '0'
'6', '2016-06-06', '23:00:00', '0', '0', '0', '0', '0', '0'
'7', '2016-06-07', '23:00:00', '0', '0', '0', '0', '0', '0'
'8', '2016-06-08', '23:00:00', '0', '0', '0', '0', '0', '0'
'9', '2016-06-09', '23:00:00', '0', '0', '0', '0', '0', '0'
'10', '2016-06-10', '23:00:00', '0', '0', '0', '0', '0', '0'
'11', '2016-06-11', '23:00:00', '0', '0', '0', '0', '0', '0'
'12', '2016-06-12', '23:00:00', '0', '0', '0', '0', '0', '0'
'13', '2016-06-13', '23:00:00', '0', '0', '0', '0', '0', '0'
'14', '2016-06-14', '23:00:00', '0', '0', '0', '0', '0', '0'
'15', '2016-06-15', '23:00:00', '0', '0', '0', '0', '0', '0'
'16', '2016-06-16', '23:00:00', '0', '0', '0', '0', '0', '0'
'17', '2016-06-17', '12:31:22', '4', '1', '0', '0', '0', '3'
이 다음 수 있습니다 :
이 지금 나 Excel에서 누적 그래프 (I 달의 시작에서 항목을했다, 그래서 6월 1일부터 16일까지에서 스푸핑 항목)를 만들 수있는 형식으로 멋진 데이터를 출력 시간에 사람이 그들이 할 수있는 그것을 사용하고 싶어 그래서 만약
이
select * from glpi.glpi_plugin_ns_ticketstats
where month(daterun)=month(NOW())
내가 여기를 떠날거야, 모두 감사하고 :)
012,351,641 도움 : 내게는
select
그래서는 현재 달 Excel로 가져 취득을
iFr4g의
가능한 복제 [범위에없는 날짜를 기입하는 방법 MySQL은?] (http://stackoverflow.com/questions/3538858/mysql-how-to-fill-missing-dates-in-range) – Shadow
나는 당신이 전체 목록을 얻으려고 긴급 목록과 날짜에 데카르트 조인을 만들어야한다고 덧붙입니다. – Shadow
스키마를 게시하거나 sqlfiddle.com에서 스키마를 생성하십시오 – CiroRa