sql积累

1.在流水表多条数据中分页查询最新的一条

SELECT tt.*
FROM myTable tt
INNER JOIN
    (SELECT ID, MAX(Date) AS MaxDateTime
    FROM myTable
    GROUP BY ID) groupedtt 
ON tt.ID = groupedtt.ID 
AND tt.Date = groupedtt.MaxDateTime

 2.查询表中每列不为空的条数

select count(case when mac!='' then '1' end) as
        macCount,
        count(case
        when phone!='' then '1' end) as phoneCount,count(case when
        imei!=''
        then '1' end) as imeiCount,count(case when imsi!='' then '1'
        end) as
        imsiCount from basic_resources_info_cluster where toDate(time) =
        #{createDate}

 

posted @ 2020-10-30 16:20  smile_lg  阅读(65)  评论(0编辑  收藏  举报