ݿͣMy SQL
IPַ127.0.0.1
˿ڣ3606
ݿ⣺work
ûroot
룺root

//============ͳ============//
ͳƲѯ䣺
select CAST( count(*) AS CHAR) from online_people where area in ('󶴶ǰ','','ͳ');
ҶͳƲѯ䣺
select CAST( count(*) AS CHAR) from online_people where area in ('Ҷǰ','Ҷ','ͳ');
 


//============Աб============//

//=====λ=====//

//ʱʾģʽΪʱ//
λԱбѯ䣺
select Name,Position,DATE_FORMAT(UpdateTime,'%H:%i'),Subdomain  from online_people where Area in ('󶴶ǰ','','ͳ') order by UpdateTime desc;
Ҷλбѯ䣺
select Name,Position,DATE_FORMAT(UpdateTime,'%H:%i'),Subdomain  from online_people where Area in ('Ҷǰ','Ҷ','ͳ') order by UpdateTime desc;

//ʱʾΪʱ//
λԱбѯ䣺
select Name,Position,DATE_FORMAT(EnterTime,'%H:%i'),Subdomain  from online_people where Area in ('','ͳ') order by EnterTime desc;
Ҷλбѯ䣺
select Name,Position,DATE_FORMAT(EnterTime,'%H:%i'),Subdomain  from online_people where Area in ('Ҷ','ͳ') order by EnterTime desc;


//=====ȷλ=====//

//ʱʾģʽΪʱ//
󶴾ȷλԱбѯ䣺
select Name,Position,DATE_FORMAT(UpdateTime,'%H:%i'),FORMAT(Location,1)  from online_people where Area in ('','ͳ') order by UpdateTime desc;
ҶȷλԱбѯ䣺
select Name,Position,DATE_FORMAT(UpdateTime,'%H:%i'),FORMAT(Location,1)  from online_people where Area in ('Ҷ','ͳ') order by UpdateTime desc;

//ʱʾģʽΪʱ//
󶴾ȷλԱбѯ䣺
select Name,Position,DATE_FORMAT(EnterTime,'%H:%i'),FORMAT(Location,1)  from online_people where Area in ('','ͳ') order by EnterTime desc;
ҶȷλԱбѯ䣺
select Name,Position,DATE_FORMAT(EnterTime,'%H:%i'),FORMAT(Location,1)  from online_people where Area in ('Ҷ','ͳ') order by EnterTime desc;

//============ͳ============//

󶴳ѯ䣺
select CAST( count(*) AS CHAR) from online_people where area= '' and Position='';

Ҷѯ䣺
select CAST( count(*) AS CHAR) from online_people where area= 'Ҷ' and Position='';

ѯ䣺
select CAST( count(*) AS CHAR) from online_people where area in ('Ҷ','ͳ') and Position='';


//============ְλͳ============//

ְλѯ䣺
select CAST( count(*) AS CHAR) from online_people where area= '' and Position='';

Ҷְλѯ䣺
select CAST( count(*) AS CHAR) from online_people where area= 'Ҷ' and Position='ܼ';




//============ͳ============//

󶴲ѯ䣺
select CAST( count(*) AS CHAR) from online_people where area= '' and Branch='ҵλ';

Ҷѯ䣺
select CAST( count(*) AS CHAR) from online_people where area= 'Ҷ' and Branch='ҵλ';


󶴶ಿϲѯ䣺
SELECT CAST( count(*) AS CHAR) FROM online_people WHERE `Branch` in ('Ŀ','˾','3','4','5','6','7') and area='';

Ҷಿϲѯ䣺
SELECT CAST( count(*) AS CHAR) FROM online_people WHERE `Branch` in ('Ŀ','˾','3','4','5','6','7') and area='Ҷ';

ѯ䣺
select CAST( count(*) AS CHAR) from online_people where area in ('Ҷ','','ǰҵ') and Branch='ҵλ';



//============ͳԱб============//

󶴶ಿбϲѯѯ䣺
select Name,Position,Branch,DATE_FORMAT( UpdateTime,'%H:%i')  from online_people where Area = '' and Branch in ('˾','Ŀ','3','4','5','6','7');

Ҷಿбϲѯѯ䣺
select Name,Position,Branch,DATE_FORMAT( UpdateTime,'%H:%i')  from online_people where Area = 'Ҷ' and Branch in ('˾','Ŀ','3','4','5','6','7');


//============б============//

ѯ䣺
select FactorName,format(`VALUE`,1),(SELECT Unit FROM em_factor WHERE Ip=(SELECT Ip FROM em_device WHERE `Name`='') AND FactorName=`Name`),CONCAT((SELECT LowerLimit FROM em_factor WHERE Ip=(SELECT Ip FROM em_device WHERE `Name`='') AND FactorName=`Name`),'-',(SELECT UpperLimit FROM em_factor WHERE Ip=(SELECT Ip FROM em_device WHERE `Name`='') AND FactorName=`Name`)) from em_realtime where DeviceId=(SELECT Id FROM em_device WHERE `Name`='');

Ҷѯ䣺
select FactorName,format(`VALUE`,1),(SELECT Unit FROM em_factor WHERE Ip=(SELECT Ip FROM em_device WHERE `Name`='Ҷ') AND FactorName=`Name`),CONCAT((SELECT LowerLimit FROM em_factor WHERE Ip=(SELECT Ip FROM em_device WHERE `Name`='Ҷ') AND FactorName=`Name`),'-',(SELECT UpperLimit FROM em_factor WHERE Ip=(SELECT Ip FROM em_device WHERE `Name`='Ҷ') AND FactorName=`Name`)) from em_realtime where DeviceId=(SELECT Id FROM em_device WHERE `Name`='Ҷ');

Ʋѯ䣺
select FactorName,format(`VALUE`,1),(SELECT Unit FROM em_factor WHERE Ip=(SELECT Ip FROM em_device WHERE `Name`='') AND FactorName=`Name`),CONCAT((SELECT LowerLimit FROM em_factor WHERE Ip=(SELECT Ip FROM em_device WHERE `Name`='') AND FactorName=`Name`),'-',(SELECT UpperLimit FROM em_factor WHERE Ip=(SELECT Ip FROM em_device WHERE `Name`='') AND FactorName=`Name`)) from em_realtime where DeviceId=(SELECT Id FROM em_device WHERE `Name`='');





select Name,(SELECT Position FROM persons WHERE CardId=pr.CardId),DATE_FORMAT(Time,'%H:%i'),''  from persons_record pr where Direction = ''  and area in ('Ҷ','','ǰҵ') and Time > DATE_ADD(NOW(), INTERVAL - 30 MINUTE) order by Time desc;






SELECT
	*
FROM
	(
		SELECT
			`Name` AS ,
			`Position` AS ְλ,
			FORMAT(Location, 1) AS ,
			'' AS ,
			DATE_FORMAT(EnterTime, '%H:%i') AS ʱ
		FROM
			online_people
		WHERE
			Area IN ('ǰ')
		UNION ALL
			SELECT
				A.`Name` AS ,
				(
					SELECT
						B.`Position`
					FROM
						persons B
					WHERE
						B.CardId = A.CardId
				) AS ְλ,
				'0' AS ,
				'' AS ,
				DATE_FORMAT(A.Time, '%H:%i') AS ʱ
			FROM
				persons_record A
			WHERE
				A.Time > DATE_ADD(NOW(), INTERVAL - 30 MINUTE)
			AND A.Direction = ''
			AND NOT EXISTS (
				SELECT
					C.CardId
				FROM
					online_people C
				WHERE
					C.CardId = A.CardId
			)
			AND NOT EXISTS (
				SELECT
					*
				FROM
					persons_record D
				WHERE
					A.CardId = D.CardId
				AND a.Time < Time
			)
	) QueryEnterExitOnlinePerson

