sql兩個字段相除 sql語句

2021-10-11 23:11:21 字數 1342 閱讀 6590

1. 查詢資料庫中某乙個欄位的個數統計

1.1. 根據統計的字段的個數進行降序排列並取前十

2. 根據乙個建立的表的值對另乙個表的值進行查詢

3. left join合併兩個表

select state, count(*) from location

left join (

select location_id from project)

on location.id = location_id

where country =='us'

group by state

order by count(*) desc

4. 將查詢結果當做乙個表

select pledged/count as pld_count,count(*),state from

(select count(*) as count, projectid from "comments"

group by projectid), project #結果表+project表

where id == projectid

group by pld_count

order by count(*) desc

5. 計算兩個字段相除

select g1,t2*1.0/t1as ratio from

SQL語句order by兩個字段同時排序問題

可能對不少來說非常簡單,但是我覺得在一定程度上對我還是有些迷惑之處,下面就通過hibernate中的hql語句來介紹下這類問題的效果。首先hql語句 from topic t where t.id 2 order by t.type desc,t.number desc也可以按照下面的寫法 from...

GROUP BY 兩個字段

create table test a varchar 10 b varchar 10 c int insert into test values a 甲 1 insert into test values a 甲 1 insert into test values a 甲 1 insert int...

需要對兩個字段分別排序的sql語句寫法

今天寫了乙個sql語句需要對乙個表的兩個字段進行排序。我的寫法如下 private static final string get shoppv recommend list select from shop pv where recommend 1 order by recommendfloat ...