I want to set display sequence for all users
i have taken select box for set sequence
where i have displayed total no of users like now total records are 5 then i will display
1,2,3,4,5
id name sequence
------------------------
1 Steve 3
2 lee 2
3 Lisa 1
4 John 0
5 smith 0
But when i am going to edit tab sequence for John i want to display 4 OR 5 in select box
because 1,2,3 are already used for other users
Can i manage all things in single query
Please advice
Related
I have control dashboard where multiple tables are listed with query
And in dashboard I can switch it to one table from ALLData to User1Table... and vice versa.
When there is only one table chosed I can easily manipulate data. However, I am struggling with updating rows when ALLData(all tables) are listed in dashboard. I can update it checking each table. I was wondering is there any better way to update it.
Tables have no DR. All tables have same column names.
//ALLData
SELECT * FROM users1
UNION ALL
SELECT * FROM users2...
user1
id name tel status
1 Bob 911 1
user2
id name tel status
3 Anna 11 0
3 Jack 12 1
//ALLData in dashboard
id name tel status
1 Bob 911 1
3 Anna 11 0
3 Jack 12 1
I can use id and status as PK
So first of all, I have 2 table. The first one is the categories
Id Name
------------
1 Interior
2 Eksterior
3 Display
then the secon table is history which the data is the task I've finished
Id category_name category_id date (month) User Id
---------------------------------------------------------------
001 Interior 1 3 1084
002 Eksterior 2 3 1084
003 Interior 1 4 1089
004 Eksterior 2 4 1085
005 Display 3 4 1085
and what I want is to get categories by month, user id and know which one already done and not done from history, like this
example the data in March with user id 1084 :
Id Name Status
---------------------------
1 Interior done
2 Eksterior done
3 Display not done
or like this :
Id Name Status
--------------------------
1 Interior 1
2 Eksterior 1
3 Display 0
if the category in history table exist, the status will be 1 for done and 0 for not done.
this is my query before :
SELECT c.id, c.category, c.id=h.category_id status FROM categories c, history h WHERE MONTH(h.created_at)
I keep retrieving the wrong result for my query. Please help me..
Seems like:
SELECT *
FROM
categories c
LEFT JOIN history h on h.category_id = c.id AND h."date (month)" = 3
..will get you towards what you want: there will be NULL in the row from history table, for category Display; you can use this "is or is not null" to create your done/not done column
I'm learning MySQL (via mode) and am approaching the Advanced section. I have a dataset that contains events that recur and I want to add a column that identifies the first, second, third, fourth, etc (no limit) occurrence of the events for that day.
CustomerID ActivityType Day Sequence
Adam Inquiry 1 1
Barb Inquiry 1 2
Adam Inquiry 1 3
Charlie Inquiry 1 4
Barb Order 1 5
Charlie Inquiry 1 6
Adam Inquiry 1 7
Barb Order 1 8
I've searched here for problems that seem similar, to help focus my learning but I don't see anything quite the same.
My desired output would be the same as above but with an added column that shows the sequence of recurring combinations of customer and activity, like this:
CustomerID ActivityType Day Sequence Recur
Adam Inquiry 1 1 1
Barb Inquiry 1 2 1
Adam Inquiry 1 3 2
Charlie Inquiry 1 4 1
Barb Order 1 5 1
Charlie Inquiry 1 6 2
Adam Inquiry 1 7 3
Barb Order 1 8 2
In MySQL 8.0, you can simply use window function ROW_NUMBER() for that purpose:
SELECT
t.*,
ROW_NUMBER() OVER(PARTITION BY customerID, ActivityType ORDER BY Sequence) recur
FROM mytable t
Note: As commented by Strawberry, storing that information in a additional column does not make a lot of sense, because it can be complicated to maintain: for example, if your table is updated, you will potentially need to recompute the whole column. You would better compute the information on the fly when querying the table.
I'm building a e-Commerce platform (PHP + MySQL) and I want to add a attribute (feature) to products, the ability to specify (enable/disable) the selling status for specific city.
Here are simplified tables:
cities
id name
==========
1 Roma
2 Berlin
3 Paris
4 London
products
id name cities
==================
1 TV 1,2,4
2 Phone 1,3,4
3 Book 1,2,3,4
4 Guitar 3
In this simple example is easy to query (using FIND_IN_SET or LIKE) to check the availability of product for specific city.
This is OK for 4 city in this example or even 100 cities but will be practical for a large number of cities and for very large number of products?
For better "performance" or better database design should I add another table to table to JOIN in query (productid, cityid, status) ?
availability
id productid cityid status
=============================
1 1 1 1
2 1 2 1
3 1 4 1
4 2 1 1
5 2 3 1
6 2 4 1
7 3 1 1
8 3 2 1
9 3 3 1
10 3 4 1
11 4 3 1
For better "performance" or better database design should I add
another table
YES definitely you should create another table to hold that information likewise you posted rather storing in , separated list which is against Normalization concept. Also, there is no way you can gain better performance when you try to JOIN and find out the details pf products available in which cities.
At any point in time if you want to get back a comma separated list like 1,2,4 of values then you can do a GROUP BY productid and use GROUP_CONCAT(cityid) to get the same.
I have a SharePoint list with 5 options (questions). Each option has a dropdown with values 1-6. The user (employee of a company) needs to select an option, then select a value from the dropdown and hit Submit. The selected value is unique. In other words, if the user selects the value 1 for the first option, that value cannot be chosen again. Here's an example form -
Category Rank
------------------------------
1. Work/Life Balance 4
2. Compensation 2
3. Commute 3
4. Work 1
5. Development 5
After filling the form, the data looks likes this on the Sharepoint list -
Employee Manager Work/Life Compensation Commute Work Development
--------------------------------------------------------------------------------
1. Employee 1 Manager 1 2 4 3 1 5
2. Employee 2 Manager 3 1 3 4 5 2
3. Employee 3 Manager 1 5 4 2 3 1
4. Employee 4 Manager 2 4 1 5 2 3
I'm able to get the Y-axis (for Rank) on the report just fine. The X-axis needs to display each category grouped by each Manager. Here's a sample of how I want it to look like -
Each colored bar on the X-axis is a Manager. This is my first time with SSRS (2012) and I'm just not sure how to accomplish this. If this is not possible, will moving the data to a SQL table in a different layout help? Any help is greatly appreciated.
You could aggregate each employee's response into an average in your dataset (I'm assuming you know how to do this):
Averages (just pretend)
Manager Work/Life Compensation Commute Work Development
--------------------------------------------------------------------------------
1. Manager1 2 4 3 1 5
2. Manager3 1 3 4 5 2
3. Manager2 4 1 5 2 3
Then you can use the categories as you have, with the manager as the series field. Pretty sure that should achieve what you're looking for.