Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
164 views
in Technique[技术] by (71.8m points)

sql server - different number of rows for a few different fields in one column

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'
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...