如何在sql server 2008中选择列表 [英] How to select list in sql server 2008

查看:101
本文介绍了如何在sql server 2008中选择列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Everybody,



如何从列表中选择值

示例:

veh_no dist

-------------------------------------------- -

AP3456 45

KN6344 56

KN6344 78

TN3851 108







对于上面的例子,如何选择基于三个veh_no的距离总和,我们无法定义veh_no ='AP3456'和'KN6344'和'TN3851'......可以输入车辆号码



结果集

dist

------------



134

108

Hello Everybody,

How to select values from List
EXAMPLE:
veh_no dist
----------------------------------------------
AP3456 45
KN6344 56
KN6344 78
TN3851 108



For the above example, how to select sum of distance based on three veh_no where we can't define veh_no='AP3456' and'KN6344' and 'TN3851'... vehicle number list may be input

Resultset
dist
------------
45
134
108

推荐答案

您可以将count函数与group by函数一起使用来获得这些结果



You can use the count function with the group by function to get these results

select veh_no,
       count(dist) as Distance
from   -- TableName
group by veh_no


这篇关于如何在sql server 2008中选择列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆