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 6105171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:55:37+00:00 2026-05-23T13:55:37+00:00

I need a query that will have the date, a user’s name, and one

  • 0

I need a query that will have the date, a user’s name, and one of twelve operation_id’s for that date. eg

operations
"id";"name";
"1";"LASER CUTTING"
"2";"DEBURR"
"3";"MACHINING"
"4";"BENDING"
"5";"PEM"
"6";"WELDING"
"7";"PAINT PREPARATION"
"8";"PAINTING"
"9";"SILKSCREEN PREPARATION"
"10";"SILKSCREEN"
"11";"ASSEMBLY - PACKAGING"
"12";"LASER PREP";

and a users table

bob
jimmeh
jimbo

I have a cross join between those tables to get something like this:

bob 1
bob 2
bob 3
bob 4
bob 5
bob 6
bob 7
bob 8
bob 9
bob 10
bob 11
bob 12
jimmeh 1
jimmeh 2
jimmeh 3
jimmeh 4
jimmeh 5
jimmeh 6
jimmeh 7
jimmeh 8
jimmeh 9
jimmeh 10
jimmeh 11
jimmeh 12
jimbo 1
jimbo 2
jimbo 3
jimbo 4
jimbo 5
jimbo 6
jimbo 7
jimbo 8
jimbo 9
jimbo 10
jimbo 11
jimbo 12

But I would also like to cross join every day between January 1st of 2011 and now so that I can use this query to give me a record for every person for every operation for every day so that I can put it in a pivot table and then use that to drive a report for each week for each user for each operation.

As of now I have a simple select userid from db.users join operations where departmentid = 8

I tried this:

select 
  userid, 
    first_name, 
    last_name,
    operations.id,
    operations.name
from 
  protocase.tblusers 
join
  operations
join
  select (BETWEEN "2011-01-01" and NOW())
where 
  departmentid = 8 and 
    protocase.tblusers.active = 1

Similar to how one would select (1,2,3) or something else that’s not from a table, but I can’t seem to figure out how I would select all the dates between January 1st and now. Is this even possible?

  • 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-05-23T13:55:37+00:00Added an answer on May 23, 2026 at 1:55 pm

    You could create a date table like this http://www.techrepublic.com/blog/datacenter/simplify-sql-server-2005-queries-with-a-dates-table/326

    Edit: Added stored procedure to generate dates:

    DROP PROCEDURE IF EXISTS datePopulate;
    DELIMITER $$
    CREATE PROCEDURE datePopulate( startDate datetime, numDays int)
    BEGIN
    
    declare currDate datetime default startDate;
    declare i int default 1;
    
    WHILE (i<=numDays) DO       
    
        INSERT INTO DateLookup(DateFull, fullYear, weekdayname) 
        VALUES(currDate, date_format(currDate, '%Y'), date_format(currDate, '%a'));
        SET i = i+1;
        SET currDate = DATE_ADD(currDate , INTERVAL 1 DAY);
    
    END WHILE;
    
    END $$
    DELIMITER ;
    

    Once procedure is created, it can be called like this:

    CALL datePopulate('2011-01-01', 30);
    

    This will populate the table with 30 days starting at 2011-01-01.

    I didn’t add all the columns in the insert statement. Should be pretty straight forward to add though using information from here.

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

Sidebar

Related Questions

I need a query that will return a table where each column is the
Database has tables Photos and PhotoAlbums. I need a query that will select all
I need to write a query that will group a large number of records
I need to write some sql that will allow me to query all objects
I have a query that I need to execute that I do not know
I have a bunch of user accounts that I need to create associations with
I have a date parameter (@rptMonth) that is selected by the user from a
I need a SQL query that returns ContactDate, SortName, City, ContactType, and Summary from
I need to do a query that search for a text with 'Nome %
I need to write a query that returns all object less that or equal

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.