我正在尝试制作一份报告,显示每天上一次我们大楼的某扇门是打开的。
到目前为止我得到的是一个函数,它返回日期(varchar(10)一次(varchar(5))当我给它一个@datestart =日期,我想开始一个报告(结束日期设置为GETDATE ())和@id_door(我们在每个门的特定id下存储锁的日期和时间)。 看起来像这样:LAST_DOOR_TIME(@DATESTART,@ ID_DOOR) 输出:
from selenium import webdriver
import time
driver = webdriver.Chrome()
driver.get('https://www.aopa.org/learntofly/school/')
driver.find_element_by_id('searchTerm').send_keys('All')
time.sleep(5)
driver.find_element_by_id('btnSearch').click()
time.sleep(3)
for items in driver.find_elements_by_xpath('//td/a'):
driver.execute_script(items.get_attribute('href'))
time.sleep(3)
for docs in driver.find_elements_by_xpath('//div[@id="schoolDetail"]'):
print(docs.text)
# Instead of docs I wanted to print the two expressions but can't
# Name = docs.find_elements_by_xpath('//div[@id="schoolDetail"]/text()[1]')
# Address = docs.find_elements_by_xpath('//div[@id="schoolDetail"]/text()[2]')
# print(Name, Address)
for back_links in driver.find_elements_by_xpath('//div[@id="schoolDetail"]//h4/a'):
driver.execute_script(back_links.get_attribute('href'))
driver.quit()
我的愿望是从@output表中选择*。我正在创建这样的:
+-------------+--------+
| DATE | TIME |
+-------------+--------+
| 28.06.2017 | 22:30 |
+-------------+--------+
| 29.06.2017 | 21:30 |
+-------------+--------+
此外,我使用一个循环来选择所有具有他们ID的门并在WHILE条件下使用它,并且在每次传递时都会更改函数中的@ID_DOOR。
我真正想要的是如何将函数的输出插入@output表,以便匹配右列和日期。
感谢您的任何建议。
好的,我的源表是: Amb_door - 表示门打开时的表。
DECLARE @output TABLE (ID int IDENTITY(1,1) not null, Date VARCHAR(10)
null, Door1 VARCHAR(5) NULL, Door2 VARCHAR(5) NULL, .... PRIMARY KEY (ID))
DECLARE @DATESTART DATE = 'some date'
DECLARE @DATEEND DATE = GETDATE()
WHILE ( @DATESTART < @DATEEND )
BEGIN
INSERT INTO @output (Date) VALUES( @DATESTART )
SELECT @DATESTART = DATEADD(DAY, 1, @DATESTART )
END
+----+-------------+-------+--------+
| id | Date | Door1 | Door2 |
+----+-------------+-------+--------+
| 1 | 28.06.2017 | | |
+----+-------------+-------+--------+
| 2 | 29.06.2017 | | |
+----+-------------+-------+--------+
| 3 | 30.06.2017 | | |
+----+-------------+-------+--------+
接下来我得到了internal_doc
+-------------+----------------------+
| ID_INT | DATE_NAV |
+-------------+----------------------+
| 1 | 2012-06-28 11:00:00 |
+-------------+----------------------+
| 2 | 2012-06-28 11:10:00 |
+-------------+----------------------+
为了从中获取相关信息,我必须在int_id上加入这两个以获得合适的门和正确的时间。我将此连接的输出放入@Temp表中,然后使用select with inner join来获取每天的最大时间。
+-------------+--------+-------------+---------+
| ID_INT | ID_EMP | ID_BUILDING | ID_DOOR |
+-------------+--------+-------------+---------+
| 1 | 1 | 3 | 10 |
+-------------+--------+-------------+---------+
| 2 | 1 | 3 | 10 |
+-------------+--------+-------------+---------+
该功能内部全部为LAST_DOOR_TIME。
答案 0 :(得分:1)
使用这些源表:
declare @AMB_DOOR table(id_INT int,date_nav datetime)
insert into @AMB_DOOR values (1, '2016-01-01 16:50')
insert into @AMB_DOOR values (2, '2016-01-01 17:20')
insert into @AMB_DOOR values (3, '2016-01-01 16:53')
insert into @AMB_DOOR values (4, '2016-01-01 17:21')
declare @INTERNAL_DOC table(id_INT int,id_EMP int,id_BUILDING int,id_DOOR int)
insert into @INTERNAL_DOC values (1,1,2,10)
insert into @INTERNAL_DOC values (2,1,3,10)
insert into @INTERNAL_DOC values (3,1,2,20)
insert into @INTERNAL_DOC values (4,1,3,20)
您可以按照以下方式获得所需内容
select
id_door,
convert(date, date_nav) as [Date],
max(convert(varchar(8), convert(time, date_nav))) as Maxtime
from
@AMB_DOOR t1 left join @INTERNAL_DOC t2 on t1.id_int=t2.id_INT
group by
id_door,
convert(date, date_nav)
给出
ID_DOOR DATE MAXTIME
10 2016-01-01 17:20:00
20 2016-01-01 17:21:00