Author Topic: Need a query  (Read 3120 times)

kirank05

  • Newbie
  • *
  • Posts: 1
    • View Profile
Need a query
« on: April 20, 2009, 12:52:41 AM »
Hi,

  I have a table contains 100 columns i need to write a query using group by and order by clauses.can you please help me in this.



Mike

  • Administrator
  • Hero Member
  • *****
  • Posts: 2025
    • View Profile
Re: Need a query
« Reply #1 on: April 20, 2009, 07:22:29 AM »
This is an example of syntax for the GROUP BY clause:

    SELECT column1, column2, ... column_n, aggregate_function (expression)
    FROM tables
    WHERE predicates
    GROUP BY column1, column2, ... column_n;


aggregate_function can be a function such as SUM, COUNT, MIN, or MAX.


Here's an example that uses the COUNT function:

SELECT department, COUNT(*) as "Number of employees"
FROM employees
WHERE salary > 25000
GROUP BY department;



Here's an example that uses the MIN function:

SELECT department, MIN(salary) as "Lowest salary"
FROM employees
GROUP BY department;