different number of rows for a few different fields in one column

末鹿安然 提交于 2019-12-13 23:42:57

问题


Can someone help? I have an existing query below(SQL Server) that is running and pulls thousands of rows.However, I need to select a specific number of rows for a few different field values in one of the column in 'vw_client_uli_member_type' table. Where and how do I pit this condition? Thank you.

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:


If you need to limit the number of rows, just add at the end of the query:

LIMIT number_rows

if you're using MySQL, or

SELECT TOP number_rows

if you're using SQL Server.

See more here.



来源:https://stackoverflow.com/questions/45843922/different-number-of-rows-for-a-few-different-fields-in-one-column

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!