..udayaAnthaya..

Monday, September 21, 2009

SQL PIVOT – resulting rows in to columns in sql

In some cases you’ll have to generate cross-tabulation reports to summarize data. Most popular method in these kinds of situations is using a “Select Case” clause. But it’ll be more easier and effective if you use the PIVOT.
PIVOT provides syntax that is simpler and more readable than what may otherwise be specified in a complex series of SELECT...CASE statements.
A common scenario where PIVOT can be useful is when you want to generate cross-tabulation reports to summarize data.

This is how it is done:
The table:
-------------------------------------------------------------------------------------















Result:
-------------------------------------------------------------------------------------




Query:
-------------------------------------------------------------------------------------

SELECT 'Averagevalue' AS Value_Sorted_By_IndividualFund,
[US Vector Equity] as Fund1, [Clean Energy Fd], [Dodge & Cox Intl Stock],[Emerging Growth],[Energy Adm]
FROM
(SELECT IndividualFund, value
FROM Funds) AS SourceTable
PIVOT
(
avg(value)
FOR IndividualFund IN ([US Vector Equity], [Clean Energy Fd], [Dodge & Cox Intl Stock], [Emerging Growth],[Energy Adm])
) AS PivotTable


Query explained:
-------------------------------------------------------------------------------------

In the result set notice that the specific columns returned come from the result of the PIVOT clause and not directly from the table (Funds)! And that PIVOT clause brings up the averages of 'value' column in each IndividualFund record, since it is used in the aggregate function avg. Another thing about PIVOT is that there can be only one aggregate function and column referenced. In this case it's avg(value).

Here the results from the original table are taken to the SourceTable. Then inside the PIVOT clause it sorted the averages against the record items that we have mentioned (in Orange color). by the first select clause in the query we retrieve the rows in the PivotTable as the result.


Important:
-------------------------------------------------------------------------------------
You can use only one aggregate function in PIVOT.

Both aliases on sub query and PIVOT clause is required. (In the case SourceTable and PivotTable)

You can set any alias to the result columns.([US Vector Equity] as Fund1)

-------------------------------------------------------------------------------------
Hope you learned something reading the article.But if not, at least you got this info for free. :)


Happy querying.


Tuesday, September 8, 2009

How Google search works


How many times for a day do you visit google? And can you imagine how many internet users visit google per minute, per day? The statistics shows that 34.7% of the global internet users visit google, where 25.72% visits yahoo which is the 2nd in the list. The secret (actually its not) of so many users relay on google is its simplicity and extraordinary quick result generating ability of the search engine. Have you ever think the technology behind this rapid and accurate search engine? In case if you are interested in finding out the answer continue reading…. The google have a well indexed database of documents which is used to query processing. That is simply it. But the hardest part is to create this database considering all the websites available in the world. Worst, the World Wide Web is very much dynamic at present. To get to know how google overcome this challenge is really interesting. Google uses parallel processing for their data processing which is a method of computation in which many calculations can be performed simultaneously, significantly speeding up data processing. The search engine of google consists of 3 distinct parts which are,

  • Googlebot
  • Indexer
  • The Query Processer


Googlebot

It is easy to explain googlebot as a spider which crawls through world wide web and retrieve pages and hands them off to the indexer. The googlebot send a request to a web server for a web page, downloading the entire page and hand it off to the Google’s indexer. Googlebot can request thousands of different pages simultaneously. To avoid traffic and crowding in web servers with human users, the Googlebot deliberately makes requests of each individual web server more slowly than it’s capable of doing. Another functionality of Googlebot is it visits sites which updates more often other that sites which are updated seldom. For an example Googlebot will visit CNN.com or slstockexchange.com 10 times per hour where it visits kln.ac.lk once a month. This helps the users to retrieve most up-to-data as possible.

Indexer

After getting the full text of the pages which handed over by the Googlebot, the indexer sorted and stored the pages in the index database. This index is sorted alphabetically by search term, with each index entry storing a list of documents in which the term appears and the location within the text where it occurs. This data structure allows rapid access to documents that contain user query terms. To improve search performance, Google ignores (doesn’t index) common words called stop words (such as the, is, on, or, of, how, why, as well as certain single digits and single letters). Stop words are so common that they do little to narrow a search, and therefore they can safely be discarded. The indexer also ignores some punctuation and multiple spaces, as well as converting all letters to lowercase, to improve Google’s performance.


The Query Processer

The query processor has several parts, including the user interface (search box), the “engine” that evaluates queries and matches them to relevant documents, and the results formatter. Google considers over a hundred factors in computing a rank to a page and determining which are most relevant to a query, including the popularity of the page, the position and size of the search terms within the page, and the proximity of the search terms to one another on the page. A patent application discusses other factors that Google considers when ranking a page. Indexing the full text of the web allows Google to go beyond simply matching single search terms. Google gives more priority to pages that have search terms near each other and in the same order as the query. Google can also match multi-word phrases and sentences.

This simple diagram shows how google process a query.

Tuesday, June 2, 2009

What is the best programming language

Arguing what is the best programming language is like arguing what is the best religion. You can never judge this because people have diverse needs, they always judge with different criteria and their knowledge of each programming language might be vary. That’s why it is told the “programming language debate” is a “religious war”. On the other hand for developers, there is no point of arguing what is the best such as when a developer is asked to repair old software which is written in COBOL dose it matters weather what is the best language?

But, as developers its better for us to be aware of the latest trends and the to check whether our programming skills are still up to date or to make a strategic decision about what programming language should be adopted when starting to build a new software system.

To measure the new trends and the popularity of the programming languages we can consider the following points:
• New applications written in the language
• Existing applications written in the language
• Developers that use the language primarily
• Developers that use the language ever
• Web searches
• Available jobs that require skills in the language
• Developers’ favorites
Here are some surveys I found in the internet which attempt to rank which programming languages are most popular, each using a different measure. The results are a bit different with each other


Source:www.Computerworld.com




Source:www.tiobe.com

These are a few statistics available in the internet. They may give you an idea about haw popular the programming languages are. It seems like now the new trend is C# where Java and VB is a little less popular than C#.


Finally, I went through this article “10 Programming Languages You Should Learn Right Now”, you should check on this because it describes what are the new trends of languages , a small description about them and why u should learn that language and even the numbers of jobs available for each language. I think it might be useful for the developers to get to know about them.

Labels: