一列中几个不同字段的不同行数

时间:2017-08-23 15:31:18

标签: sql-server tsql sql-server-2012 rows

有人可以帮忙吗?我在下面有一个现有的查询(SQL Server)正在运行并提取数千行。但是,我需要在< vw_client_uli_member_type'中的一列中为一些不同的字段值选择特定数量的行。表。我在哪里以及如何养成这种情况?谢谢。

select ind_int_code as 'Individual Type',
ind_first_name as 'First Name',
ind_last_name as 'Last Name',
cst_recno as 'Member ID',
cst_eml_address_dn as 'Email Address',
adr_city as 'City',
adr_state as 'State' ,
adr_country as 'Country',
cst_org_name_dn as 'Company',
cst_ixo_title_dn as 'Job Title',
mem_member_type as 'Member Type'
FROM 
co_individual  WITH (NOLOCK) 
JOIN co_individual_ext  WITH (NOLOCK)  ON ind_cst_key_ext=ind_cst_key 
JOIN co_customer  WITH (NOLOCK)  ON cst_key=ind_cst_key and ind_delete_flag=0
and ind_deceased_flag=0 
LEFT JOIN co_customer_x_address  WITH (NOLOCK)  ON cst_cxa_key=cxa_key 
LEFT JOIN co_address  WITH (NOLOCK)  ON adr_key=cxa_adr_key 
LEFT JOIN vw_client_uli_member_type  WITH (NOLOCK)  ON cst_key=mem_cst_key 
WHERE mem_member_type Is Not Null AND mem_expire_date >= '8/22/2017' AND adr_country = N'UNITED STATES' AND ind_deceased_flag != 1 AND ind_key_leader_flag_ext != 1 AND ind_int_code != N'Staff' AND ind_int_code != N'Spouse' AND ind_int_code != N'Press'

1 个答案:

答案 0 :(得分:0)

如果您需要限制行数,只需在查询末尾添加:

LIMIT number_rows

如果您使用的是MySQL,或

SELECT TOP number_rows

如果您使用的是SQL Server。

查看更多here