mysql数据库,多表查询

含有关键字的单表查询:

SELECT count(*) FROM `email` where subject like '%工商%' and ip is not null


多表查询,并按某关键项给出的段进行查询

将一个账户下有多张账单的emailid取出来,分银行(sql语句),BillAmountInfo下有多条

 

SELECT

     *

FROM

     billAmountInfo AS ofb,

     billBaseInfo AS b

WHERE ofb.billBaseInfoId = b.id

AND b.bankCode = "CGB"

AND b.billDate>="2014-11-01"AND b.billDate<="2014-12-01"

GROUP BY

     ofb.billBaseInfoId

HAVING

     COUNT(ofb.billBaseInfoId) >1 AND COUNT(ofb.billBaseInfoId)<3


联表查询

SELECT

*

FROM

email AS e

LEFT JOIN emailAccount AS et ON e.emailAccountId = et.id

LEFT JOIN  billBaseInfo AS bo ON e.id = bo.emailId

WHERE et.mailAccount = "[email protected]"

AND bo.emailId is NOT NULL


猜你喜欢

转载自blog.csdn.net/wudiyi815/article/details/42148661