计数记录并显示特殊字段

时间:2018-04-13 20:38:00

标签: sql count

ID  case    date    time
----------------------------------
101  A      2001    1
101  A      2002    2
102  A      2001    1
103  B      2001    1
101  B      2003    1
101  A      2004    3
102  C      2006    1
101  B      2007    2
103  C      2007    1

什么是SQL查询

用于ID,计算每个案例并显示时间1的日期。

样品: ID = 101的输出:

ID  case    date    qty
-------------------------------------
101  A      2001    3
101  B      2003    2

请指导我。

3 个答案:

答案 0 :(得分:0)

以下查询基于您的示例输出。 你可以试试这个

$("#textBoxId").attr("disabled", "disabled");

答案 1 :(得分:0)

感谢您的帮助。我找到了答案。

select id, case, min(time), count(*) as qty
from table
group by id, case
having id=101

答案 2 :(得分:0)

我想你想要:

SELECT id, case, count(*) as qty, max(case when time = 1 then date end) as date
FROM table
WHERE id = 101
GROUP BY id, case