Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8728619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:40:54+00:00 2026-06-13T08:40:54+00:00

I have a table named Sample which looks like. I want the output as

  • 0

I have a table named Sample which looks like.

enter image description here

I want the output as following enter image description here

for this I have built the following Query:

SELECT YEAR/MONTH, 1L,3L,4L,6L,8L
    FROM (
    SELECT PANEL, LAYERCOUNT, MONTHS
    FROM Sample) up
    PIVOT (SUM(Count) FOR CountOFL IN (1L,3L,4L,6L,8L)) AS pvt
    ORDER BY YEAR/MONTH

But it gives error Incorrect syntax near ‘1’.

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T08:40:55+00:00Added an answer on June 13, 2026 at 8:40 am

    For the table structures you gave, this query would return the pivoted table on the CountOFL column:

    SELECT YEARMONTH, [1L],[3L],[4L],[6L],[8L]
    FROM Sample
    PIVOT (SUM(RecordCount) FOR CountOFL IN ([1L],[3L],[4L],[6L],[8L])) AS pvt
    ORDER BY YEARMONTH
    

    Results:

    YEARMONTH                        1L          3L          4L          6L          8L
    -------------------------------- ----------- ----------- ----------- ----------- -----------
    Dec2011                          2           NULL        NULL        NULL        NULL
    Jan2011                          NULL        4           NULL        NULL        NULL
    Jul2012                          2           NULL        5           NULL        NULL
    Jun2011                          NULL        NULL        NULL        NULL        1
    Jun2012                          2           NULL        NULL        1           NULL
    May2011                          NULL        5           NULL        NULL        NULL
    Sep2012                          NULL        1           NULL        NULL        NULL
    

    So, you need to enclose the values of the PIVOTed column in square brackets.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table named datas and I'm executing a query like this: SELECT
I have an intermediate table which looks something like this (after I join 2
I have a table which looks like this: Name | Quantity | Unit -------+-------------+----------
I have a query that looks like the following SELECT t1.Name, t2.ID, t2.name FROM
I have a table named size here, something like this: size id | size
I have a table that looks something like this: CREATE TABLE student_results(id integer, name
Suppose I have a simple MySQL table that looks like this: CREATE TABLE `my_table`
I have a MySQL table that looks like this: Table: Designer id: integer name:
I have a simple database named customer with a single table data.I want to
I have a table named tbl_Subjects_Taken which lists all the subjects taken by the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.