如何计算SQL中不同表的时差?

时间:2017-03-14 06:01:57

标签: mysql sql sql-server mysql-workbench

我有两张桌子。我想计算年差。 这是表" lulus":

enter image description here

这是表" mahasiswa"

enter image description here

从图中可以看出,我已经标记了Tanggal Lulus和Tahun Masuk,我想计算" TahunMasuk - TahunLulus" 。有没有办法计算它们虽然 TahunMasuk 只有年份?

2 个答案:

答案 0 :(得分:1)

您可以使用类似

的内容
SELECT m.TahunMasuk - YEAR(l.TahunLulus) 
   FROM lulus l left join mahasiswa m on l.MahasiswaId = m.MahasiswaId

您应该根据需要调整查询,因为我不知道连接这两个表的字段是什么。我刚刚做了一个假设。

答案 1 :(得分:0)

使用像这样:

# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.support.ui import Select
import time
from selenium.webdriver.common.by import By

url = "https://www.arval.fr/"

driver = webdriver.Chrome()
driver.maximize_window()

driver.get(url)

select = Select(driver.find_element_by_id("vehicleTypeRef"))
select.select_by_visible_text("Voiture")

def getallcars():
    el = driver.find_element(By.ID,"makeRef")
    car =[]
    for option in el.find_elements(By.TAG_NAME,'option'):
        car.append((option.text).encode('utf8'))
    return car

cars=getallcars()

def printModel(cars):
    for value in cars[1:]:
        drop = driver.find_element(By.ID, 'makeRef')
        sel = Select(drop)
        sel.select_by_visible_text(value)
        time.sleep(2)
        el2 = driver.find_element(By.ID,'modelRef')
        print "The models for %s are:"  %value
        for option in el2.find_elements(By.TAG_NAME,'option'):
            if not (option.text).encode('utf8') == "Sélectionnez":
                print  option.text

printModel(cars)


select.select_by_visible_text("Véhicule de société")
time.sleep(2)
cars=getallcars()
printModel(cars)

select.select_by_visible_text("Véhicule utilitaire")
time.sleep(2)
cars=getallcars()
printModel(cars)