数据库中最最常用的语法----select.简单的select语法很直白: select column from table where expression: 从((from)存储数据的地方(table)按照(where)一定的条件(expression)查找(select)我要的数据(column); 但是在实际工作中用到的比较多的往往还是多联表查询,所以在这里记下自己学习多联表查询的心得. 首先聊一聊笛卡尔积,这是几乎所有数据库书籍在讲多联表查询时第一个要讲的东西,我等P民也只能是把笛卡尔
SELECT t4.orgName, t3.projectName, t3.Partner, t1.type, COUNT(DISTINCT t1.imei) AS count FROM `t_teminal` AS t1 LEFT JOIN `t_orgcode_orgid_rela` AS t2 ON t1.orgid = t2.orgId LEFT JOIN `t_org_code` AS t3 ON t2.topOrganizationCode = t3.topOrganizationC
表结构概述 model.py : class Something(models.Model): name = models.CharField(max_length=32) class UserType(models.Model): caption = models.CharField(max_length=32) s = models.ForeignKey('Something') #这个s不是字段名,字段名是something_id,这里的s作用是查询的时候用:row.s.id或row.s.
联表删除: 1.从数据表t1 中把那些id值在数据表t2 里有匹配的记录全删除掉 DELETE t1 FROM t1,t2 WHERE t1.id=t2.id 或DELETE FROM t1 USING t1,t2 WHERE t1.id=t2.id 2.从数据表t1里在数据表t2里没有匹配的记录查找出来并删除掉 DELETE t1 FROM t1 LEFT JOIN T2 ON t1.id=t2.id WHERE t2.id IS NULL 或 DELETE FROM t1,USIN