Hi,
I'm trying to select the top 10 entries from a table per a variable. At present the below query brings up only 10 entries but I want 10 entries per segmentcode.
SELECT top 10 * FROM t_security WHERE segmentcode IN(
'AIM','AIM3','AIMI','AMSM','ASQ1','ASQ2','ASX1','A SX2','ASXN','CIBB','CNVE','CRNR','CRTR','CSEQ','CS ET','CSQX',
'CWNR','CWNU','CWTR','CWTU','EQS','ETCS','ETF2','E TFS','GILT','INSD','IOB','IOBU','IRSQ','IRSU','ITB B','ITBU',
'ITR','LVSD','MIBB','MISC','MISL','MSEQ','MSET','M SQX','MSTM','NSTS','ODTT','PSNR','PSTR','RSET','RS TM','SET1',
'SET2','SET3','SSMM','SSMU','SSQ3','SSX3','SSX4',' STBS','STMM','TC1E','TC1M','TC1O','TCAE','TCAM','T CAO','TEST',
'XIBB','XSEQ','XSET','XSTM','ZA01','ZA02','ZA03',' ZA04','ZA11','ZA21','ZA22','ZA24'
)
1 1574
Hi,
I'm trying to select the top 10 entries from a table per a variable. At present the below query brings up only 10 entries but I want 10 entries per segmentcode.
SQL Server 2005 solution (don't forget to replace YOUR_FIELDS_HERE with correct field list, ORDER_FIELD with correct field name): - ;with Ordered(YOUR_FIELDS_HERE, Position) as
-
(
-
select YOUR_FIELDS_HERE, Position = row_number() over(partition by segmentcode order by ORDER_FIELD)
-
from t_security
-
where segmentcode in(
-
'AIM','AIM3','AIMI','AMSM','ASQ1','ASQ2','ASX1','A SX2','ASXN','CIBB','CNVE','CRNR','CRTR','CSEQ','CS ET','CSQX',
-
'CWNR','CWNU','CWTR','CWTU','EQS','ETCS','ETF2','E TFS','GILT','INSD','IOB','IOBU','IRSQ','IRSU','ITB B','ITBU',
-
'ITR','LVSD','MIBB','MISC','MISL','MSEQ','MSET','M SQX','MSTM','NSTS','ODTT','PSNR','PSTR','RSET','RS TM','SET1',
-
'SET2','SET3','SSMM','SSMU','SSQ3','SSX3','SSX4',' STBS','STMM','TC1E','TC1M','TC1O','TCAE','TCAM','T CAO','TEST',
-
'XIBB','XSEQ','XSET','XSTM','ZA01','ZA02','ZA03',' ZA04','ZA11','ZA21','ZA22','ZA24'
-
)
-
)
-
select YOUR_FIELDS_HERE
-
from Ordered
-
where Position<=10
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Nathan Sokalski |
last post by:
When testing a form of mine which uses RequiredFieldValidators that have the
Display property set to "Dynamic" the ErrorMessage property is automatically
removed when an entry is completely typed...
|
by: Bob Loveshade |
last post by:
I am looking for an example that shows how to select and highlight
multiple rows in a DataGrid.
My DataGrid is part of a Web User Control which is contained in an ASPX
page.
I haven't been...
|
by: Jed Parsons |
last post by:
Hi,
I'm using the logging module for the first time. I'm using it from
within Zope Extensions.
My problem is that, for every event logged, the logger is producing
multiple identical entries...
|
by: Bernard Lebel |
last post by:
Hello,
Is there an option or a way to allow the selection of multiple entries
in the Listbox widget? I could not find any, and would like to allow
the end user to select multiple entries.
...
|
by: Henrik Goldman |
last post by:
Hi there,
I'm new to sql and thus I'm having problems with a specific query which I
hope you guys can help me with.
Basicly I have a few tables which I'm trying to do a query on:
Table...
|
by: michael.martinek |
last post by:
Greetings!
I've recently been trying to do something, which apparently looks like
it may be a little odd.. I'm not finding anything in the manuals or
anywhere on the web where something similiar...
|
by: Generic Usenet Account |
last post by:
I had a need to randomly select an element from an STL collection. It
does not appear that this functionality is provided out-of-the-box
with STL. Here is my crude implementation. I am using...
|
by: c35tar1 |
last post by:
I have a ListView within a dialog. In code the groups are created and
items added. Display is 100% correct. The problem is with using
Shift to select multiple items in the list.
- If you...
|
by: maxamis4 |
last post by:
Hello folks need some ideas here for a report that I am getting together. Here is the scenerio, currently we have an SLA that states that an external group transferring a problem to the internal...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |