473,394 Members | 1,755 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Sorting

I have an excel sheet or a table which looks like following(3 columns or field),

Part-----Assembly----Avg
5------- 12.5------- 15
4------- 20--------- 5
2------- 35--------- 30
1------- 14--------- 16
3------- 18--------- 21

(It is an example, May be I will have thousands of records)

This data is collected from simulation run (do not bother).

Now what I want is the following,

First,  Find the smallest number from 2 columns (Assembly and Avg),
For example, here the smallest number is 5, which is in Avg column.

Second  If the smallest number found in Column (Avg) than place the entire
record at the beginning of the table, or if the smallest number found in column(Assembly) than place the entire record at the end of the table.

Note: You can use another table or excel sheet to insert the sorted record or the same sheet or table.

Therefore, from the above table we get the following,

Part-----Assembly----Avg
4------- 20----------- 5
2------- 35------------ 30
3------- 18------------ 21
1------- 14------------ 16
5------- 12.5-----------15


Therefore, the prime thing is to find the smallest number first and place the record on table according to the columns (Assembly, Avg) and to keep in mind that after each search the found number must be eliminated to find the next smallest. The whole process should run at once.

I have no idea about it how to place record on a table according to above requirement.

Please provide me some solution for that.
You can write code for Excel macro (VBA) or visual basic coding or SQL query. Any of the form would be accepted. I just need the logic to do this.
May 13 '10 #1
1 1302
Not sure if you will have found a solution to this but the following concept should work:
  • Find the minimum of the columns.
  • If it is from the Assembly column, multiply it by -1.
  • Create a new column which has either a 1 or 2 in it, 1 if it came from Average and 2 if it came from Assembly
  • Sort the data by the new column and then by the modified minimum

An example of this which works in SQL

Expand|Select|Wrap|Line Numbers
  1. SELECT   partID
  2.          ,myAssy
  3.          ,myAvg
  4.          ,CASE
  5.              WHEN  myAssy < myAvg
  6.              THEN  myAssy * -1
  7.              ELSE  myAvg
  8.          END AS myMin
  9.          ,CASE
  10.              WHEN  myAssy < myAvg
  11.              THEN  2
  12.              ELSE  1
  13.          END AS myMinType
  14. FROM     dbo.R_Table
  15. ORDER BY myMinType
  16.          ,myMin
You can probably remove the CASE statements from the SELECT and just recreate them in the ORDER BY but I have not tried this.
Jun 8 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: dont bother | last post by:
This is really driving me crazy. I have a dictionary feature_vectors{}. I try to sort its keys using #apply sorting on feature_vectors sorted_feature_vector=feature_vectors.keys()...
0
by: ck388 | last post by:
For some reason when I enable the callback feature of the gridview I still get a page refresh, that is it seems like there is a postback that occurs, not a callback which is just supposed to update...
7
by: Federico G. Babelis | last post by:
Hi All: I have this line of code, but the syntax check in VB.NET 2003 and also in VB.NET 2005 Beta 2 shows as unknown: Dim local4 As Byte Fixed(local4 = AddressOf dest(offset)) ...
19
by: Owen T. Soroke | last post by:
Using VB.NET I have a ListView with several columns. Two columns contain integer values, while the remaining contain string values. I am confused as to how I would provide functionality to...
10
by: Sjaakie | last post by:
Hi, I'm, what it turns out to be, fooling around with 3-tier design. At several websites people get really enthusiastic about using custom dataobjects instead of datasets/-tables. While trying to...
4
by: Ambica Jain | last post by:
Hi, I want custom sorting on some of the columns in the datagrid. And i am able to do the same by overriding MouseDown event. However, i need to rebind my datatable to reflect the changes in...
7
by: Kamal | last post by:
Hello all, I have a very simple html table with collapsible rows and sorting capabilities. The collapsible row is hidden with css rule (display:none). When one clicks in the left of the...
1
KevinADC
by: KevinADC | last post by:
Introduction In part one we discussed the default sort function. In part two we will discuss more advanced techniques you can use to sort data. Some of the techniques might introduce unfamiliar...
5
by: lemlimlee | last post by:
hello, this is the task i need to do: For this task, you are to develop a Java program that allows a user to search or sort an array of numbers using an algorithm that the user chooses. The...
5
by: jrod11 | last post by:
hi, I found a jquery html table sorting code i have implemented. I am trying to figure out how to edit how many colums there are, but every time i remove code that I think controls how many colums...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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...
0
tracyyun
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.