简体   繁体   English

如何在结果窗格列的每个“最小”值中添加“更大”过滤器

[英]How to add 'greater' filter to every 'minimum' value in a result pane column

I have the following syntax: 我有以下语法:

SELECT t1.cardid, t1.Name, t2.record
FROM t2 INNER JOIN t1 on t1.tag=t2.tag GROUP BY t1.cardid, t1.name

the result come out like this: 结果出来像这样:

cardid      name       record
100         Dan        09:00
100         Dan        10:00
200         Jane       06:00
200         Jane       09:00
399         Lisa       07:00
399         Lisa       13:00
500         Kane       10:00
500         Kane       12:10
500         Kane       13:50

Now I add a 'min' filter and modify the syntax to become like this: 现在,我添加一个“最小”过滤器,并将语法修改为如下形式:

SELECT t1.cardid, t1.Name, min(t2.record) As Record
FROM t2 INNER JOIN t1 on t1.tag=t2.tag GROUP BY t1.cardid, t1.name

The result become like this: 结果变成这样:

cardid      name       record
100         Dan        09:00
200         Jane       06:00
399         Lisa       07:00
500         Kane       10:00

How do I add a filter so that only the 'minimum value' of each record that has more than; 如何添加过滤器,以使每个记录的“最小值”都大于 say '08:00' value come out in the "record" column. 说“ 08:00”值出现在“记录”列中。 The result I want is something like this: 我想要的结果是这样的:

cardid      name       record
100         Dan        09:00
500         Kane       10:00

I'm using SQL. 我正在使用SQL。

SELECT t1.cardid, t1.Name, min(t2.record) As Record
FROM t2 INNER JOIN t1 on t1.tag=t2.tag
GROUP BY t1.cardid, t1.name
having min(t2.record) >= cast('08:00' as time)

I suppose record is also time type, also you can use convert('08:00', time) or even try without cast/convert, it can work too, as mysql can do automatic casting 我想记录也是时间类型,也可以使用convert('08:00', time)甚至尝试不进行强制转换/转换,它也可以工作,因为mysql可以自动强制转换

for very old mysql you can try to use having 0+substring(t2.record, 1,2) >= 8 对于非常老的mysql,您可以尝试使用having 0+substring(t2.record, 1,2) >= 8

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM