SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    Keep it simple, stupid! bokehman's Avatar
    Join Date
    Jul 2005
    Posts
    1,935
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Add a field to a result for a column that doesn't exist

    Ok, here's my query:
    Code:
    SELECT 
      transponders.orb_pos, satellites.sat_name, transponders.frequency, transponders.symbol_rate, transponders.polarisation, transponders.fec_inner, transponders.DVB_system, transponders.modulation
     FROM
      transponders, satellites
     WHERE
       transponders.orb_pos = satellites.orb_pos 
      AND
       transponders.feed = 0
     ORDER BY
      transponders.orb_pos, transponders.frequency ASC
    I want my result to also contain a variable call "band". If "transponders.frequency" is less than 10000 it will contain the string "C", otherwise it will contain the string "Ku". Or would I be better off just running a second query with an additional AND clause?

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,338
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    compare how the CASE expression reads against your requirement...
    Code:
    SELECT transponders.orb_pos
         , satellites.sat_name
         , transponders.frequency
         , transponders.symbol_rate
         , transponders.polarisation
         , transponders.fec_inner
         , transponders.DVB_system
         , transponders.modulation
         , CASE WHEN transponders.frequency < 10000
                THEN 'C
                ELSE 'Ku' END   AS band
      FROM transponders
    INNER
      JOIN satellites
        ON satellites.orb_pos = transponders.orb_pos
     WHERE transponders.feed = 0
    ORDER 
        BY transponders.orb_pos
         , transponders.frequency
    p.s. you should be writing explicit JOINs nowadays
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •