Horizontal List of Items Sharing Same Image Data Information - duplicates

I am trying to extract from a vertical list of Items that share the same Image URL to display the just one instance of the shared URL with all of the shared items listed as a horizontal string with a ~ separator.
So from the following data:
File | Item |
| -------- | -------------- |
| product-image.jpg | Item1 |
| product-image.jpg | Item2 |
| product-image.jpg | Item3 |
| product-image.jpg | Item4 |
| product-image.jpg | Item5 |
| product-image.jpg | Item6 |
| product-image2.jpg | Item7 |
| product-image2.jpg | Item8 |
| product-image2.jpg | Item9 |
| product-image2.jpg | Item10 |
| product-image2.jpg | Item11 |
| product-image2.jpg | Item12 |
I would like to have the following output (with the added~)
File | Item |
| -------- | -------------- |
| product-image.jpg | Item1~Item2~Item3~Item4~Item5~Item6~ |
| product-image2.jpg | Item7~Item8~Item9~Item10~Item11~Item12~ |
Would this type of operation be viable in VBA (with SQL?), and if so, how?
Thanks!

Related

How to replace words in one table for row numbers in another

I have two tables:
________________________ ________________________________
| id | categoryName | | product | categories |
------------------------ --------------------------------
| 1 | clothes | | coat | clothes,outdoor |
| 2 | indoor | | slippers | clothes,indoor |
| 3 | PPE | | umbrella | outdoor,ppe |
| 4 | outdoor | | | |
------------------------ --------------------------------
I need to replace the values in the categories field in the second table for the category IDs in the first table so the tables would end up looking like this:
________________________ ________________________________
| id | categoryName | | product | categories |
------------------------ --------------------------------
| 1 | clothes | | coat | 1,4 |
| 2 | indoor | | slippers | 1,2 |
| 3 | PPE | | umbrella | 4,3 |
| 4 | outdoor | | | |
------------------------ --------------------------------
Since I have so many to update I am trying to work out how to do it programatically, but am struggling with it.

mySQL query not returning unique prices for each option

I am running the following mySQL query which is returning the incorrect price for each product option. (Each option has a different price for testing purposes).
How can I return the individual prices for each option?
The DB schema can be seen here:
http://www.webassist.com/tutorials/Free-eCommerce-MySQL-Database
SELECT ProductName AS productname, ProductCategoryID,
pov.OptionGroupName AS groupname,
povd.OptionName AS optionname,
pd.OptionPrice as price
FROM products p
LEFT JOIN productoptions pd ON (p.ProductID = pd.ProductID)
LEFT JOIN optiongroups pov ON (pd.OptionGroupID = pov.OptionGroupID)
LEFT JOIN options povd ON (pov.OptionGroupID = povd.OptionGroupID)
WHERE p.ProductID = 1
GROUP BY groupname, povd.OptionName
Currently getting this (note the prices):
+-------------+-------------------+-----------+------------+-------+
| ProductName | ProductCategoryID | GroupName | OptionName | Price |
+-------------+-------------------+-----------+------------+-------+
| Item1 | 1 | Color | Black | 2.00 |
| Item1 | 1 | Color | Red | 2.00 |
| Item1 | 1 | Color | Blue | 2.00 |
| Item1 | 1 | Size | Small | 5.00 |
| Item1 | 1 | Size | Medium | 5.00 |
+-------------+-------------------+-----------+------------+-------+
Should be like this (with unique prices):
+-------------+-------------------+-----------+------------+-------+
| ProductName | ProductCategoryID | GroupName | OptionName | Price |
+-------------+-------------------+-----------+------------+-------+
| Item1 | 1 | Color | Black | 2.00 |
| Item1 | 1 | Color | Red | 3.00 |
| Item1 | 1 | Color | Blue | 4.00 |
| Item1 | 1 | Size | Small | 5.00 |
| Item1 | 1 | Size | Medium | 6.00 |
+-------------+-------------------+-----------+------------+-------+
Here are data sets for all tables concerned (thanks for the guidance, Strawberry!).
Products Table
+-----------+-------------+-------------------+
| ProductID | ProductName | ProductCategoryID |
+-----------+-------------+-------------------+
| 1 | T-Shirt1 | 1 |
+-----------+-------------+-------------------+
OptionGroups Table
+---------------+-----------------+
| OptionGroupID | OptionGroupName |
+---------------+-----------------+
| 1 | color |
| 2 | size |
+---------------+-----------------+
ProductOptions Table
+-----------------+-----------+----------+-------------+---------------+
| ProductOptionID | ProductID | OptionID | OptionPrice | OptionGroupID |
+-----------------+-----------+----------+-------------+---------------+
| 1 | 1 | 1 | 2.00 | 1 (color) |
| 2 | 1 | 2 | 3.00 | 1 (color) |
| 3 | 1 | 3 | 4.00 | 1 (color) |
| 4 | 1 | 4 | 5.00 | 2 (size) |
| 5 | 1 | 5 | 6.00 | 2 (size) |
+-----------------+-----------+----------+-------------+---------------+
Options Table
+----------+---------------+------------+
| OptionID | OptionGroupID | OptionName |
+----------+---------------+------------+
| 1 | 1 | black |
| 2 | 1 | red |
| 3 | 1 | blue |
| 4 | 2 | Small |
| 5 | 2 | Small |
+----------+---------------+------------+
I took your query, scaisEdge, and made some changes to it. I removed the min/max stuff, changed the way the Left Join was done on ProductOptions, and changed the Where clause and Group By. Seems to be working correctly:
+-------------+-------------------+-----------+------------+-------+
| ProductName | ProductCategoryID | GroupName | OptionName | Price |
+-------------+-------------------+-----------+------------+-------+
| Item1 | 1 | Color | Black | 2.25 |
| Item1 | 1 | Color | Red | 3.25 |
| Item1 | 1 | Color | Blue | 4.25 |
| Item1 | 1 | Size | Small | 5.25 |
| Item1 | 1 | Size | Medium | 6.25 |
+-------------+-------------------+-----------+------------+-------+
The Query at this point:
SELECT ProductName AS productname, ProductCategoryID,
pov.OptionGroupName AS groupname,
povd.OptionName AS optionname,
pd.OptionPrice AS price,
povd.OptionID AS optionid
FROM products p
LEFT JOIN productoptions pd ON (pd.OptionID = optionid)
LEFT JOIN optiongroups pov ON (pd.OptionGroupID = pov.OptionGroupID)
LEFT JOIN options povd ON (pov.OptionGroupID = povd.OptionGroupID)
WHERE p.ProductID = 1 and povd.OptionID = pd.OptionID
GROUP BY povd.OptionID,
groupname, povd.OptionName
Thanks a lot for your help on this, scaisEdge.
And thanks to Strawberry for guiding me on how to format my questions on the site.
I truly believe that if a member 'down-votes' a question they should be required to explain why, so that we newbies can learn without simply being demoted and learning nothing from it.

How to create a MySQL view to show all paths for each node in a nested set model through a related table?

I have two tables, categories and products. Categories table is a nested set model. Products table has a serial_number field that is unique. Their schema is like this :
Categories :
+----+-----------+-----+-----+-------+-------------+
| id | parent_id | lft | rgt | depth | title |
+----+-----------+-----+-----+-------+-------------+
| 1 | Null | 2 | 9 | 0 | Cloth |
| 2 | 1 | 3 | 6 | 1 | Men's |
| 3 | 2 | 4 | 5 | 2 | Suits |
| 4 | 1 | 7 | 8 | 1 | Women's |
| 5 | Null | 10 | 13 | 0 | Electronics |
| 6 | 5 | 11 | 12 | 1 | TVs |
+----+-----------+-----+-----+-------+-------------+
Products :
+-------------+---------------+
| category_id | serial_number |
+-------------+---------------+
| 3 | 5461354631 |
| 3 | 4521516545 |
| 4 | 8513453217 |
| 6 | 1235624165 |
+-------------+---------------+
What I want is to create a view to show all serial_numbers with their category path :
+---------------+-------------------+
| serial_number | path |
+---------------+-------------------+
| 5461354631 | Cloth/Men's/Suits |
| 4521516545 | Cloth/Men's/Suits |
| 8513453217 | Cloth/Women's |
| 1235624165 | Electronics/TVs |
+---------------+-------------------+
What is the best query to generate this view?

Selected Child Categories based on parent categories from another table

I have two tables
rules
With three step hierarchy
|id | name | parent |
|---|-------|--------|
| 1 | A | 0 |
| 2 | B | 0 |
| 3 | A(1) | 1 |
| 4 | A(2) | 1 |
| 5 | B(1) | 2 |
| 6 | A(1.1)| 3 |
| 7 | A(1.2)| 3 |
| 8 | A(2.1)| 4 |
| 9 | B(1.1)| 5 |
| 10| A(3) | 1 |
Subject
|id | date | rules | group |
|---|---------------------|-------|-------|
| 1 | 2016-05-20 18:24:20 | 2 | AQR48 |
| 2 | 2016-05-20 19:31:17 | 5 | AQR52 |
| 3 | 2016-05-21 18:11:37 | 6,7,4 | AQR48 |
I need to get second step rules based on group and ruleid(first step) of subject table data
When group = 'AQR48' and rules.parent=1 result should be
|id | name | parent |
|---|-------|--------|
| 3 | A(1) | 1 |
| 4 | A(2) | 1 |
I tried it like this but with out success.
select rules.id,rules.name,rules.parent from rules left join subject on find_in_set(rules.id,subject.rules) where rules.parent=1 AND subject.group='AQR48'
With this I get output as
|id | name | parent |
|---|-------|--------|
| 4 | A(2) | 1 |
Anyone could help me with this

Is it possible to put the grouping field on top of the table in SSRS?

Is it possible to do this kind of layout in SSRS?
2012/11/01
-----------------------------
| Order # | Product | Qty |
-----------------------------
| | Mouse | 3 |
| 1 | Keyboard | 2 |
| | CPU | 5 |
-----------------------------
| | Mouse | 1 |
| 2 | Keyboard | 7 |
| | Lan Cable | 7 |
-----------------------------
2012/11/02
-----------------------------
| Order # | Product | Qty |
-----------------------------
| | Mouse | 2 |
| | Keyboard | 8 |
| 3 | Memory | 4 |
| | CPU | 2 |
| | Battery | 1 |
-----------------------------
I tried finding a property that could do that, tried dragging the field on top too but to no avail :-)
Yes you can do this, it's easiest if you nest two tablixes (a table inside a list). Make a list that groups on the date field. Inside the list place the table that groups rows on the order id. This would look like this:
----
2012/11/01 |
----------------------------- |
| Order # | Product | Qty | |
----------------------------- |
| | Mouse | 3 | |
| 1 | Keyboard | 2 | | --- List item 1
| | CPU | 5 | |
----------------------------- |
| | Mouse | 1 | |
| 2 | Keyboard | 7 | |
| | Lan Cable | 7 | |
----------------------------- |
----
----
2012/11/02 |
----------------------------- |
| Order # | Product | Qty | |
----------------------------- |
| | Mouse | 2 | | --- List item 2
| | Keyboard | 8 | |
| 3 | Memory | 4 | |
| | CPU | 2 | |
| | Battery | 1 | |
----------------------------- |
----
Alternatively you can make one big table:
group rows on the date
below that, group rows on the order id
create a group header for the topmost group, merge the cells in the header, and display the date there
In this approach I'm not 100% sure if you can easily repeat the headers with each item in the date-group.