2016-04-13 16 views
1

Açıklamak zor bir tane, Aşağıdaki kod, farklı olan bir sütuntan değerleri seçmek için kullanıyorum ve daha sonraBaşka bir SQL'ye bağımlı bir sütundan bir değer SEÇME ile ilgili sorun

örn.

product 1 = 100 
product 2 = 52 

ancak statü denilen bir değişik Kolon = rezervasyon, ben bu kullanılarak yapılabilir biliyorum nerede satırları kullanmak için bu ihtiyaç NEREDE status = yere kodda booking ama konumlandırma hakkı alamayan, herhangi bir yardım?

select distinct product, count(product) as CountOf 
from sw_orders 
group by product 

Numune veri kümesi

id | product | status 
----------------------- 
1 | pd1  | non 
2 | pd2  |booking 
3 | pd4  |booking 
4 | pd2  |cancelled 
5 | pd1  |booking 
6 | pd1  |booking 
7 | pd1  |booking 

beklenen sonuç

product| count 
----------------------- 
pd1 | 3 
pd4 | 1 
pd2 | 1 
+0

Örnek veriler ve istenen sonuçlar size yardımcı olacaktır. Muhtemelen basit şartlı toplamadır. – lad2025

cevap

1

Basit koşullu toplanmasına kullanabilirsiniz:

SELECT product, SUM(status = 'booking') as CountOf 
FROM sw_orders 
GROUP BY product; 
0

deneyin

İlgili konular