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