A. 一个sql查询根据两个字段分组问题
可以这样写
select * from table where title like '%a%'
union
select * from table where context like '%a%'
B. SQL 按两个字段分组
selectMODELNO,COLORfrom表名groupbyMODELNO,COLOR
表名换下
这样能分组
但是你可能还有别的东西要做吧,这样只是把组分了呀
C. 已知 ,数据库两个字段,年,月。现在要按照季度分组查询,怎么写sql语句
先case when将月份变成季度,然后再group by即可,SQL如下:
select year, quarter, count(1)
from (
select year,
case
when month < 4 then 1
when month < 7 then 2
when month < 10 then 3
else 4
end as quarter
from table
) as result
group by year, quarter
D. SQL如何查询一张表的所有字段并按其中一个字段进行分组
1、创建测试表,
create table test_group_cols(id number, value varchar2(20), remark varchar2(20));
E. sql语句按照两个字段分组然后查询出每一组中的最大值。
select a,b,max(c) c
from tab
group by a,b
F. 用SQL按两个字段分组查询
SELECT month,no,money=SUM(MONEY) FROM TABLENAME GROUP BY MONTH,NO ORDER BY MONTH,NO
上面是第一个结果。
第二个这样得到:
select month as [m-n],
(select sum(money) from tablename b where b.month=a.month and b.no=1) as [1],
(select sum(money) from tablename b where b.month=a.month and b.no=2) as [2],
(select sum(money) from tablename b where b.month=a.month and b.no=3) as [3]
from
(select distinct month from tablename) a