Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. An SQL Statistics

An SQL Statistics

Scheduled Pinned Locked Moved Database
databasetutorial
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    foryou
    wrote on last edited by
    #1

    Hi! I work on an intranet site of a university(sqlserver2005) and I need to do statistics for example I need to count the students new in the semester 2 for each city: Here is the SQL query that selects the new students in semester 2:

    WITH r1 AS (SELECT CAPITALISE_SEMESTRE_1.NUM_INSCRIPTION, CAPITALISE_SEMESTRE_1.CODE_SEMESTRE , CAPITALISE_SEMESTRE_1.ann_uni, SEMESTRE_1.LIBELLE_SEMESTRE_AR,
    TYPE_RELATION_SEMESTRE_1.LIBELLE_TYPE_RELATION_SEMESTRE
    FROM CAPITALISE_SEMESTRE AS CAPITALISE_SEMESTRE_1 INNER JOIN
    SEMESTRE AS SEMESTRE_1 ON CAPITALISE_SEMESTRE_1.CODE_SEMESTRE = SEMESTRE_1.CODE_SEMESTRE INNER JOIN
    TYPE_RELATION_SEMESTRE AS TYPE_RELATION_SEMESTRE_1 ON
    CAPITALISE_SEMESTRE_1.CODE_TYPE_RELATION_SEMESTRE = TYPE_RELATION_SEMESTRE_1.CODE_TYPE_RELATION_SEMESTRE
    WHERE (CAPITALISE_SEMESTRE_1.CODE_TYPE_RELATION_SEMESTRE = 4) AND (CAPITALISE_SEMESTRE_1.CODE_SEMESTRE = 2)),
    r2 AS
    (SELECT CAPITALISE_SEMESTRE.NUM_INSCRIPTION AS Expr1, CAPITALISE_SEMESTRE.CODE_SEMESTRE AS Expr2,
    SEMESTRE.LIBELLE_SEMESTRE_AR AS Expr3,CAPITALISE_SEMESTRE.ann_uni AS Expr4
    FROM CAPITALISE_SEMESTRE AS CAPITALISE_SEMESTRE INNER JOIN
    SEMESTRE AS SEMESTRE ON CAPITALISE_SEMESTRE.CODE_SEMESTRE = SEMESTRE.CODE_SEMESTRE INNER JOIN
    TYPE_RELATION_SEMESTRE AS TYPE_RELATION_SEMESTRE ON
    CAPITALISE_SEMESTRE.CODE_TYPE_RELATION_SEMESTRE = TYPE_RELATION_SEMESTRE.CODE_TYPE_RELATION_SEMESTRE
    WHERE (CAPITALISE_SEMESTRE.ann_uni = @ann_uni) AND (CAPITALISE_SEMESTRE.CODE_SEMESTRE = 1))
    SELECT r1_1.NUM_INSCRIPTION, r1_1.ann_uni,r1_1.CODE_SEMESTRE, r1_1.LIBELLE_SEMESTRE_AR, r1_1.LIBELLE_TYPE_RELATION_SEMESTRE, r2_1.Expr1,
    r2_1.Expr2, r2_1.Expr3, r2_1.Expr4
    FROM r1 AS r1_1 INNER JOIN
    r2 AS r2_1 ON r1_1.NUM_INSCRIPTION = r2_1.Expr1

    but I do not know how to calculate the number for each city: Number of sudent new in semester2------------City 12222---------------------------------city1 123----------------------------------city2 Thanks.

    M 1 Reply Last reply
    0
    • F foryou

      Hi! I work on an intranet site of a university(sqlserver2005) and I need to do statistics for example I need to count the students new in the semester 2 for each city: Here is the SQL query that selects the new students in semester 2:

      WITH r1 AS (SELECT CAPITALISE_SEMESTRE_1.NUM_INSCRIPTION, CAPITALISE_SEMESTRE_1.CODE_SEMESTRE , CAPITALISE_SEMESTRE_1.ann_uni, SEMESTRE_1.LIBELLE_SEMESTRE_AR,
      TYPE_RELATION_SEMESTRE_1.LIBELLE_TYPE_RELATION_SEMESTRE
      FROM CAPITALISE_SEMESTRE AS CAPITALISE_SEMESTRE_1 INNER JOIN
      SEMESTRE AS SEMESTRE_1 ON CAPITALISE_SEMESTRE_1.CODE_SEMESTRE = SEMESTRE_1.CODE_SEMESTRE INNER JOIN
      TYPE_RELATION_SEMESTRE AS TYPE_RELATION_SEMESTRE_1 ON
      CAPITALISE_SEMESTRE_1.CODE_TYPE_RELATION_SEMESTRE = TYPE_RELATION_SEMESTRE_1.CODE_TYPE_RELATION_SEMESTRE
      WHERE (CAPITALISE_SEMESTRE_1.CODE_TYPE_RELATION_SEMESTRE = 4) AND (CAPITALISE_SEMESTRE_1.CODE_SEMESTRE = 2)),
      r2 AS
      (SELECT CAPITALISE_SEMESTRE.NUM_INSCRIPTION AS Expr1, CAPITALISE_SEMESTRE.CODE_SEMESTRE AS Expr2,
      SEMESTRE.LIBELLE_SEMESTRE_AR AS Expr3,CAPITALISE_SEMESTRE.ann_uni AS Expr4
      FROM CAPITALISE_SEMESTRE AS CAPITALISE_SEMESTRE INNER JOIN
      SEMESTRE AS SEMESTRE ON CAPITALISE_SEMESTRE.CODE_SEMESTRE = SEMESTRE.CODE_SEMESTRE INNER JOIN
      TYPE_RELATION_SEMESTRE AS TYPE_RELATION_SEMESTRE ON
      CAPITALISE_SEMESTRE.CODE_TYPE_RELATION_SEMESTRE = TYPE_RELATION_SEMESTRE.CODE_TYPE_RELATION_SEMESTRE
      WHERE (CAPITALISE_SEMESTRE.ann_uni = @ann_uni) AND (CAPITALISE_SEMESTRE.CODE_SEMESTRE = 1))
      SELECT r1_1.NUM_INSCRIPTION, r1_1.ann_uni,r1_1.CODE_SEMESTRE, r1_1.LIBELLE_SEMESTRE_AR, r1_1.LIBELLE_TYPE_RELATION_SEMESTRE, r2_1.Expr1,
      r2_1.Expr2, r2_1.Expr3, r2_1.Expr4
      FROM r1 AS r1_1 INNER JOIN
      r2 AS r2_1 ON r1_1.NUM_INSCRIPTION = r2_1.Expr1

      but I do not know how to calculate the number for each city: Number of sudent new in semester2------------City 12222---------------------------------city1 123----------------------------------city2 Thanks.

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      Somewhere in that godawful load of crap you call a query there is a join to a table that has the city in it, use group by cityname may be useful. That is one ugly query!

      Never underestimate the power of human stupidity RAH

      F 1 Reply Last reply
      0
      • M Mycroft Holmes

        Somewhere in that godawful load of crap you call a query there is a join to a table that has the city in it, use group by cityname may be useful. That is one ugly query!

        Never underestimate the power of human stupidity RAH

        F Offline
        F Offline
        foryou
        wrote on last edited by
        #3

        Thanks Mycroft Holmes; Groupby gives me no count of student in any city

        WITH r1
        AS (SELECT CAPITALISE_SEMESTRE_1.NUM_INSCRIPTION,
        CAPITALISE_SEMESTRE_1.CODE_SEMESTRE , CAPITALISE_SEMESTRE_1.CODE_TYPE_RELATION_SEMESTRE ,CAPITALISE_SEMESTRE_1.ann_uni

                             FROM         CAPITALISE\_SEMESTRE AS CAPITALISE\_SEMESTRE\_1 WHERE  (CAPITALISE\_SEMESTRE\_1.CODE\_TYPE\_RELATION\_SEMESTRE = 4) AND (CAPITALISE\_SEMESTRE\_1.CODE\_SEMESTRE = 2)), 
        

        r2 AS
        (SELECT CAPITALISE_SEMESTRE.NUM_INSCRIPTION AS Expr1, CAPITALISE_SEMESTRE.CODE_SEMESTRE AS Expr2,
        CAPITALISE_SEMESTRE.ann_uni AS Expr4
        FROM CAPITALISE_SEMESTRE AS CAPITALISE_SEMESTRE

          WHERE      (CAPITALISE\_SEMESTRE.ann\_uni = '2008/2009') AND (CAPITALISE\_SEMESTRE.CODE\_SEMESTRE = 1))
        SELECT     r1\_1.NUM\_INSCRIPTION
         FROM         r1 AS r1\_1 INNER JOIN
                                r2 AS r2\_1 ON r1\_1.NUM\_INSCRIPTION = r2\_1.Expr1
        
        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups