拥有最大订单数sql的餐厅

时间:2015-05-04 10:28:46

标签: sql-server

我是新来的,我需要的帮助不大。我有下表,我想知道哪个地址的餐馆订单数量最多。

我已经开始了这样的查询 - >

<!-- Dummy item to prevent AutoCompleteTextView from receiving focus -->

<LinearLayout
    android:focusable="true" android:focusableInTouchMode="true"
    android:layout_width="0px" android:layout_height="0px"/>

<!-- :nextFocusUp and :nextFocusLeft have been set to the id of this component
     to prevent the dummy from receiving focus again -->
<AutoCompleteTextView android:id="@+id/autotext"
    android:layout_width="fill_parent" android:layout_height="wrap_content"
    android:nextFocusUp="@id/autotext" android:nextFocusLeft="@id/autotext"/>

但这仅计算一个地址的结果。如何在一个查询(计数)中确定其他餐馆的订单,并返回哪一个订单数量最多?在列顺序1(表示餐厅有订单)和2(餐厅没有订单)

select  count(addressOfRestaurant) 
from Restaurants 
where addressOfRestaurant = 'Adress1' and orders = '1'

1 个答案:

答案 0 :(得分:0)

orders排序并仅拍摄第一条记录

select top 1 addressOfRestaurant 
from restaurants
group by addressOfRestaurant 
order by sum(orders) desc