发新话题
打印

Mysql 多表Left join 查询

Mysql 多表Left join 查询

两个表这间的查询

SELECT c.serial,c.otherserial,c.os_license_id asdate,u.name,u.firstname,u.realname from glpi_computers as c leftjoin glpi_users as u on c.FK_users=u.id

三个表之间的查询

SELECT c.serial,c.otherserial,c.os_license_id asdate,u.name,u.firstname,u.realname,s.name from (glpi_computers as cleft join glpi_users as u on c.FK_users=u.id) left joinglpi_dropdown_state as s on c.state=s.id

多个表之间的查询

SELECT c.serial as Serial_Number,c.otherserial asFA_Number,c.os_license_id as Buy_Date, l.completename asLocation,d.name as Section,m.name as Model,t.name as PC_Type,u.nameas GID,u.firstname as FirstName,u.realname as LastName,s.name asStatus
from (((((glpi_computers as c left join glpi_dropdown_domain as don c.domain=d.id) left join glpi_dropdown_model as m onc.model=m.id) left join glpi_dropdown_state as s on c.state=s.id)left join glpi_type_computers as t on c.type=t.id) left joinglpi_users as u on c.FK_users=u.id) left joinglpi_dropdown_locations as l on c.location=l.id


SELECT c.serial as Serial_Number,c.otherserial asFA_Number,c.os_license_id as Buy_Date,l.completename asLocation,d.name as Section,m.name as Model,t.name as PC_Type,u.nameas GID,u.firstname as FirstName,u.realname as LastName,s.name asStatus
from (((((glpi_computers as c left join glpi_dropdown_domain as don c.domain=d.id) left join glpi_dropdown_model as m onc.model=m.id) left join glpi_dropdown_state as s on c.state=s.id)left join
glpi_type_computers as t on c.type=t.id) left join glpi_users as uon c.FK_users=u.id) left join glpi_dropdown_locations as l onc.location=l.id


SELECT t.name as issue,c.completename as category,t.date asopendate,t.closedate,t.status FROM glpi_tracking t,glpi_dropdown_tracking_category c where t.category=c.id andc.completename like 'IT%' and t.date >'2011-07-31'and t.closedate <'2011-09-01'

TOP

发新话题