2011-04-19 70 views
-1

可能重複:
query in mysql with range用於計算基於範圍的記錄mSQL的查詢值

寫一個SQL查詢,以確定在以下工資的人的數量範圍小於1,00,000 (equal to or greater than 1,00,000)且小於5,00,000大於或等於5,00,000

輸出應該如下:

count salary_range 
10 [< 1,00,000] 
5 [> 1,00,000 and < 1,50,0000] 
22 [< 5,00,000] 
+0

如果你再次提出這個問題,至少沒有顯示_some attempt_做你的功課,你的帳戶**將被**暫停。如果您可以顯示該嘗試,請編輯您的_original_問題並將其標記爲主持人審覈。 – 2011-04-19 10:07:15

回答

0

這會不會是相同的輸出你的問題,但會給你如何做一個提示:

select (select count(*) from `persons` where salary <= '100000') as count1, 
(select count(*) from `persons` where salary > '100000' and salary <= '150000') as count2, 
(select count(*) from `persons` where salary > '150000' and salary <= '500000') as count3 

按我認爲這個問題是重複的:query-in-mysql-with-range

+0

這會工作,但會是一個表現不佳的查詢。單向透視查詢會更好。 – RichardTheKiwi 2011-04-19 09:52:27